在VB.Net中定制任意形狀的按鈕

發表于:2007-05-25來源:作者:點擊數: 標簽:任意形狀VB.NET思路按鈕
思路: 首先,創建一個Point對象數組,為按鈕定制多邊形。接著創建一個GraphicsPath對象,在其中添加多邊形。再將GraphicsPath轉化為Region。最后,將按鈕的Region屬性設置為前面得到的結果。 具體代碼: Private Sub Form1_Load(ByVal sender As System.Obj
思路:
    首先,創建一個Point對象數組,為按鈕定制多邊形。接著創建一個GraphicsPath對象,在其中添加多邊形。再將GraphicsPath轉化為Region。最后,將按鈕的Region屬性設置為前面得到的結果。
     
具體代碼:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    ' 定義多邊形路徑中的點
    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) _
    }

    ' 形成GraphicsPath
    Dim polygon_path As New System.Drawing.Drawing2D.GraphicsPath(FillMode.Winding)
    polygon_path.AddPolygon(pts)

    ' 將GraphicsPath轉為Region
    Dim polygon_region = New Region(polygon_path)

    ' 將按鈕約束在Region內
    Button1.Region = polygon_region

    ' 讓按鈕填充Region
    Button1.SetBounds(Button1.Location.X, Button1.Location.Y, pts(3).X + 5, pts(4).Y + 5)
End Sub

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97