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
Keywordsshape, polygon, button, SetWindowRgn, region, shaped button
CategoriesControls, Graphics
 
Use the CreatePolygonRegion API function to make a polygonal region. Then use SetWindowRgn to make the button use the region.

Unfortunately this makes the button lose its shaded borders. My book Custom Controls Library shows how to build some shaped buttons that still have beveled borders.

 
' Make the button arrow-shaped.
Private Sub Form_Load()
Dim pts(1 To 7) As POINTAPI

    pts(1).X = 5
    pts(1).Y = 15
    pts(2).X = 35
    pts(2).Y = 15
    pts(3).X = 35
    pts(3).Y = 5
    pts(4).X = 55
    pts(4).Y = 25
    pts(5).X = 35
    pts(5).Y = 45
    pts(6).X = 35
    pts(6).Y = 35
    pts(7).X = 5
    pts(7).Y = 35
    
    Command1.Width = ScaleX(pts(4).X + 5, vbPixels, vbTwips)
    Command1.Height = ScaleY(pts(5).Y + 5, vbPixels, _
        vbTwips)

    m_ButtonRegion = CreatePolygonRgn(pts(1), UBound(pts), _
        ALTERNATE)
    SetWindowRgn Command1.hWnd, m_ButtonRegion, True
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated