There may be a time when you get tired of the same old rectangle based form. You may even want to make the form a shape of a circle or work with skins. You needed to use Windows APIs to do it in 6.0. In VB.NET, Visual Basic 2008, VB 2010, and newer this is done pretty easily.
There are a few different ways to set your forms shape. I will use the GraphicsPath class in this article.
Variables/Objects to Make
- new – GraphicPath
- new – Region
- new – StringFormat
'Used to specify the Shapes, Text, and what-not. Dim p As Drawing2D.GraphicsPath = New Drawing2D.GraphicsPath 'The region to pass to the form once its setup. Dim reg As Region 'Used to specify the way to format the strings. Dim sf As New StringFormat
Once that is taken care of, specify what and how to display your forms region. In this example I am going to make the form a Ellipse shape and with a Text/String region as well.
'Add a shape to display the region as. p.AddEllipse(0, 0, 100, 200) ' 'Add some text to display as well. p.AddString("Visual Basic for FREE!", FontFamily.Families.GetValue(1), FontStyle.Regular, 15, New Point(100, 100), StringFormat.GenericDefault) 'Simply create a new Region object with the information in the Graphics Path. reg = New Region(p) 'And the last is to set the newly created region for the form to display. Me.Region = reg
That all there is to it. There are pretty much unlimited shapes you could make your form display as. This example works with Visual Basic.NET, Visual Basic 2008. VB 2010. and newer. Anyways, Have Fun!