Windows Develop Bookmark and Share   
 index > Windows Forms Designer > how to change border color to Gray for a Panel
 

how to change border color to Gray for a Panel

Hi

ThisPanel.BorderStyle =

BorderStyle.FixedSingle;
Now this gives the panel a border with BLACK color.. I need to change it to Gray.
How do i do it?

Thanks

dsfsdfs  Thursday, July 16, 2009 9:13 AM
Hi dsfsdfs,

You can override the Panel.OnPaint method to draw a rectangle with gray color. Here is the example
public class MyPanel : Panel
{
public MyPanel()
{
}

protected override void OnPaint(PaintEventArgs e)
{
Rectangle rec = new Rectangle(e.ClipRectangle.Location.X, e.ClipRectangle.Location.Y, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1);
e.Graphics.DrawRectangle(Pens.Gray, rec);
base.OnPaint(e);
}
}

Based on my test, if I use e.ClipRectangle as the rectangle, the right bottom side line will be invisible, so I reduce it by 1 pixel.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Monday, July 20, 2009 4:01 AM
Hi dsfsdfs,

You can override the Panel.OnPaint method to draw a rectangle with gray color. Here is the example
public class MyPanel : Panel
{
public MyPanel()
{
}

protected override void OnPaint(PaintEventArgs e)
{
Rectangle rec = new Rectangle(e.ClipRectangle.Location.X, e.ClipRectangle.Location.Y, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1);
e.Graphics.DrawRectangle(Pens.Gray, rec);
base.OnPaint(e);
}
}

Based on my test, if I use e.ClipRectangle as the rectangle, the right bottom side line will be invisible, so I reduce it by 1 pixel.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Monday, July 20, 2009 4:01 AM

You can use google to search for other answers

Custom Search

More Threads

• Adding custom designerverb (combobox)
• Styles in windows controls
• Adding images to a Context Menu
• Designer Serialization (SplitContainer, third parties etc.)
• MenuCommandsChanged not firing for all commands
• How to implement Datasource property on custom controls?
• custom calendar control
• Showing a Form when the Form name is a String
• How to code situations where there is a mustinherit class in the middle
• Strange Errors in IDE and VS Crashes