Visual Basic - Make A Real Statement With Your Forms Using The AddString Method (Visual Basic .NET)
You're probably aware that you can shape Windows forms into circles, triangles, or any other shape using a GraphicsPath object. However, did you know that you can also shape a form into a string of text? To do so, place the following code in the Load() event of a Windows application:
- Dim gPath As System.Drawing.Drawing2D. _
- GraphicsPath = New System.Drawing. _
- Me.BackColor = Color.Blue
- gPath.AddString("This is" & vbCrLf & _
- "WAY COOL!", _
- New FontFamily("Arial Black"), _
- FontStyle.Bold, 60, _
- New Point(5, 10), _
- ' Constrain the form to the region.
- Me.Region = New Region(gPath)
The AddString method creates a GraphicsPath object using the string "This is WAY COOL." Then, you just need to assign the new path to the Form's Region property. You an even use carriage returns in the string, as we've done in the sample code.