Howto add a custom border to a FormBorderStyle=None - form?

Zoef picture Zoef · Jan 25, 2013 · Viewed 29.1k times · Source

I have a form with the property FormBorderStyle set to 'None' and with a custom bar on top side for dragging and buttons.

Now I'd like to give the form a border because it's a child form and the parent form has the same background color as the child, so it's hard to see the child form. And no, I can't/won't change the background color.

Help

Answer

gunakkoc picture gunakkoc · Jan 25, 2013

There is a way without a need to set a background image and/or fixed sized form. So this is the most proper and simple way I guess. Say you have a form named Form1, all you need to do is:

Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.Black, ButtonBorderStyle.Solid)
End Sub

An alternative, if you want to use the default border provided by your Windows version:

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
    Me.Text = ""
    Me.ControlBox = False
End Sub