J
Joe Keller
Hello,
In writing custom components that, among other things, draw a border around
themselves (e.g. Panel component) I rely heavily on the "ClientRectangle()"
call to get the rectangle size of the component. However, I've found
without fail that if I rely solely on the measurements of what
ClientRectangle() returns to me, the right hand side and bottom of the
border will not be visible (it appears it is drawn past the bounds of the
component). Inevitably, I need to decrease the size of the width and the
height by 1 to get the border around the component (a rectangle) to draw
properly.
Is this expected behavior? Am I doing something incorrectly or is this
possibly a bug in how ClientRectangle() returns its results?
Sample code is listed below - just override the OnPaint() method of a Panel
component with the following code to see what I am talking about
protected override void OnPaint(PaintEventArgs e)
{
Graphics g;
Rectangle r;
Pen p;
g = e.Graphics;
r = this.ClientRectangle;
p = new Pen(Color.Black);
// If you comment out the following two lines the component will not draw
the border properly.
r.Width -= 1;
r.Height -= 1;
g.DrawRectangle(p,r);
g.Dispose();
base.OnPaint(e);
}
Thanks!
Joe
In writing custom components that, among other things, draw a border around
themselves (e.g. Panel component) I rely heavily on the "ClientRectangle()"
call to get the rectangle size of the component. However, I've found
without fail that if I rely solely on the measurements of what
ClientRectangle() returns to me, the right hand side and bottom of the
border will not be visible (it appears it is drawn past the bounds of the
component). Inevitably, I need to decrease the size of the width and the
height by 1 to get the border around the component (a rectangle) to draw
properly.
Is this expected behavior? Am I doing something incorrectly or is this
possibly a bug in how ClientRectangle() returns its results?
Sample code is listed below - just override the OnPaint() method of a Panel
component with the following code to see what I am talking about
protected override void OnPaint(PaintEventArgs e)
{
Graphics g;
Rectangle r;
Pen p;
g = e.Graphics;
r = this.ClientRectangle;
p = new Pen(Color.Black);
// If you comment out the following two lines the component will not draw
the border properly.
r.Width -= 1;
r.Height -= 1;
g.DrawRectangle(p,r);
g.Dispose();
base.OnPaint(e);
}
Thanks!
Joe