How to change the borderColor for a panel control

  • Thread starter Thread starter sajin
  • Start date Start date
S

sajin

Hi,

I am using VB .net 2005 to create my windows form application , i have
a panel control in my main form , i want to change the border color of
the panel to red color , could any one help me to resolve this problem

Thanks in advance
Sajin
 
You can set the BorderStyle of the Panel to None, and then add an event
handler for the Paint event and draw a border in whatever color, thickness,
or pattern that you'd like.
 
Derive a custom control from a Panel and add the following code to
"paint" the red border.

protected override void OnPaint(PaintEventArgs pe)
{
// TODO: Add custom paint code here
pe.Graphics.DrawRectangle(Pens.Red,
pe.ClipRectangle.Left,
pe.ClipRectangle.Top,
pe.ClipRectangle.Width - 1,
pe.ClipRectangle.Height - 1);

// Calling the base class OnPaint
base.OnPaint(pe);
}
 
Back
Top