Search code examples
vb.netvisual-studio-2010user-interfacegdi

How to draw outline around a borderless form?


I have a form that I am using as a splash screen. Since it is a splash it does not have a border on it. The splash screen is white so when it loads against something else that is white it looks funy. I was thinking of adding an outline around the form about 1 px or so to give it a thin border. Think of it as adding a stroke to an image in photoshop. How would I do this? I am using vb.net.


Solution

  • You could use GDI+:

    Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
        MyBase.OnPaintBackground(e)
    
        Dim rect As New Rectangle(0, 0, Me.ClientSize.Width - 1, Me.ClientSize.Height - 1)
    
        e.Graphics.DrawRectangle(Pens.Black, rect)
    End Sub
    

    (You can substitute any Pen for Pens.Black, of course.)