WinForm控件画边框的问题
控件画边框时代码如下:
...
Rectangle fram = Rectangle.FromLTRB(0, 0, this.Width - 1, this.Height - 1);
e.Graphics.DrawRectangle(new Pen(Brushes.Red), fram);
或:
Rectangle fram = new Rectangle(0, 0, Width - 1, Height - 1);
g.DrawRectangle(_drawPen, fram)
问题:
为什么这里的参数是Width-1和Height-1,而不是Width和Height
根据MSDN上对FromLTRB参数的定义是:
参数
left
此 Rectangle 结构左上角的 x 坐标。
top
此 Rectangle 结构左上角的 y 坐标。
right
此 Rectangle 结构右下角的 x 坐标。
bottom
此 Rectangle 结构右下角的 y 坐标。
对Rectangle参数的定义是:
参数
x
矩形左上角的 x 坐标。
y
矩形左上角的 y 坐标。
width
矩形的宽度。
height
矩形的高度。