Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Borderless Winform with a 1px border

This might sound like a weird question but I have C# Winform that I set the FormBorderStyle to None. So far everything is good but I was wondering if there was a way to add like a 1px border on around my form ? I know I could do it by creating my own image but I was wondering if there was a more natural way of doing it. Thanks

like image 791
00101010 10101010 Avatar asked Dec 04 '12 12:12

00101010 10101010


2 Answers

I consider using an image, or creating unnecessary controls for something that is easily paintable using GDI+ a waste of resources.

I think the simplest solution is overriding the OnPaint method of your form and drawing the border yourself:

protected override void OnPaint(PaintEventArgs e)
{
    e.Graphics.DrawRectangle(Pens.Black, this.Bounds);
}

Of course, you may also use your own Pen with your own color and width.

like image 177
Rotem Avatar answered Oct 06 '22 11:10

Rotem


Use padding 1;1;1;1 to your form and set a background color to your form, and put a panel to your form. Set white or other normal background color to the panel. And set dock in parent controller. The background color of the form will act as a border.

like image 33
antoncrimea Avatar answered Oct 06 '22 10:10

antoncrimea