Title | Make a shaped button in VB .NET |
Keywords | shape, polygon, button, SetWindowRgn, region, shaped button, VB .NET |
Categories | Controls, Graphics, API, VB.NET |
|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
' Define the points in the polygonal path.
Dim pts() As Point = { _
New Point(5, 15), _
New Point(35, 15), _
New Point(35, 5), _
New Point(55, 25), _
New Point(35, 45), _
New Point(35, 35), _
New Point(5, 35) _
}
' Make the GraphicsPath.
Dim polygon_path As New GraphicsPath(FillMode.Winding)
polygon_path.AddPolygon(pts)
' Convert the GraphicsPath into a Region.
Dim polygon_region = New Region(polygon_path)
' Constrain the button to the region.
Button1.Region = polygon_region
' Make the button fit the region.
Button1.SetBounds(Button1.Location.X, _
Button1.Location.Y, pts(3).X + 5, pts(4).Y + 5)
End Sub
|