The Form has a property FormBorderStyle that decides the kind of border around it. A similar property for a Control is BorderStyle. There is no way to customize these borders directly from the Form Designer. The class System.Windows.Forms.ControlPaint has the methods that come handy when you want to:
- Draw the border with a particular color say blue or yellow.
- Draw a border whose sides have different color or thickness
The MSDN link for the class is here.
Create a Windows application in Visual Studio
I have written a small program to illustrate this. Create a Windows application in Visual Studio and added a Panel – panel1, to the form, Form1 – the default form created by Visual studio. Anchor the panel to all the four sides of the form.
Add event handler for the Paint event of the Panel
Next add an event handler for the Paint event of the panel and use ControlPaint.DrawBorder method to draw a deep blue border around the panel. The panel BorderStyle must be set to none in the Form designer.
private void panel1_Paint(object sender, PaintEventArgs e)
{ControlPaint.DrawBorder(e.Graphics, this.panel1.ClientRectangle, Color.DarkBlue, ButtonBorderStyle.Solid);
}
The only problem is that when the form resizes, the panel resizes but the previous borders of the panel are not deleted. To solve this problem, just invalidate the form on panel resize.
Invalidate the Form on Panel Resize
Invalidating the form on panel Resize, triggers the Paint event of the form and all it’s controls. The panel is also repainted. This erases the previously drawn panel borders and creates a new border around the panel.
private void panel1_Resize(object sender, EventArgs e)
{
Invalidate();
}
To draw a border whose each side is different color or thickness, use the other overloaded form of DrawBorder method. To draw 3D border just use DrawBorder3D method.


Thank You
And how can we make form with a custom-color border. I mean not blue border?
You can specify the color in panel1_Paint method -
…
ControlPaint.DrawBorder(e.Graphics, this.panel1.ClientRectangle, Color.DarkBlue, ButtonBorderStyle.Solid);
…
Change the Color.DarkBlue to ypur desired color and it’s done!
Great. Exactly what i was looking for.
Instead of overriding the paint event you could simply modify the control style in the constructor:
public PanelEx(){
SetStyle(ControlStyles.ResizeRedraw, true);
Thanks for this — I used to be a fan of Delphi’s panel style with the grove or indentation or whatever, and it’s annoyed me that VS doesn’t have something analogous.
tnx a lot man