Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleMake a shaped button in VB .NET
Keywordsshape, polygon, button, SetWindowRgn, region, shaped button, VB .NET
CategoriesControls, Graphics, API, VB.NET
 
Create an array of Point objects that define the polygonal shape for the button. Create a GraphicsPath object and add the polygon to it. Convert the GraphicsPath into a Region and set the button's Region property to the result.
 
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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated