Specifying borders for a panel

  • Thread starter Thread starter marc.cueto
  • Start date Start date
M

marc.cueto

How can I do it so that I can specify which border I would like to
appear on a panel? Say for example on a panel I want all sides except
the right side to be drawn?
 
How can I do it so that I can specify which border I would like to
appear on a panel? Say for example on a panel I want all sides except
the right side to be drawn?

Have a look at the ControlPaint.DrawBorder and DrawBorder3D methods.
 
How can I do it so that I can specify which border I would like to
appear on a panel? Say for example on a panel I want all sides except
the right side to be drawn?

You may want to override the control's 'OnPaint' method and draw the borders
there using appropriate methods of the 'ControlPaint' class.
 
Thank you all for replying. I managed to get it going using this code
sample:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

Rectangle borderRectangle = this.ClientRectangle;
borderRectangle.Inflate(-10, -10);
ControlPaint.DrawBorder(e.Graphics, borderRectangle,
System.Drawing.Color.Black, 1,
System.Windows.Forms.ButtonBorderStyle.Solid,
System.Drawing.Color.Black, 1,
System.Windows.Forms.ButtonBorderStyle.Solid,
System.Drawing.Color.Black, 1,
System.Windows.Forms.ButtonBorderStyle.Solid,
System.Drawing.Color.Black, 1,
System.Windows.Forms.ButtonBorderStyle.Solid);
}
I have one last question though. The top, left and bottom borders
connect fine but the left border seems to be a little off. The top and
bottom borders run past the right border by about 1 pixel. What is the
problem?
 
That would appear to be a bug.

You can workaround it by setting the Clip Region of the graphics object to
your borderRectangle.
borderRectangle.Inflate(-10, -10);

e.Graphics.Clip = new Region(borderRectangle);
 
Back
Top