VB.NET - Code Sample - Create Round Forms

Use the system.drawing namespace to create custom shaped forms


In order to create a circular form you need to first set three properties of the form. The first is to set the formborderstyle to none. The second property to set is the TransparencyKey, which is a color. Next set the backcolor of the form to the same color as the TransparencyKey. On the windows paint event use the system.drawing namespace to draw a circular background of a color different than the TransparencyKey which will serve as the shape of the form.

The Code:

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim gr As System.Drawing.Graphics= Me.CreateGraphics()

        ' Fill the ellipse.
        gr.FillEllipse(System.Drawing.Brushes.DarkGray, 0, 0, _
            Me.ClientSize.Width - 5, _
            Me.ClientSize.Height - 5)
    End Sub
About this page: