[C#][VB.NET]簡易的圓形Button

  • 23022
  • 0
  • 2010-08-02

產生圓形的Button

這是在藍色小舖遇到的問題,如何產生圓形的按鈕,以下透過 System.Drawing 繪製圓形,並且它指派給Button的Region,

不過這個方法產生出來的圓形按鈕其實有點不好看,這只是一個小範例,也可以透過相同的方式產生圓形的Form,

但如果想要漂亮點的按鈕,可以參考Code Project 的範例

http://www.codeproject.com/KB/buttons/netimagebutton.aspx

C#

    button1.Size = new Size(50, 50);
            button1.BackColor = Color.Blue;
            System.Drawing.Drawing2D.GraphicsPath aCircle = new System.Drawing.Drawing2D.GraphicsPath();
            aCircle.AddEllipse(new Rectangle(0, 0, 50, 50));
            button1.Region = new Region(aCircle);

VB.NET

        Button1.Size = New Size(50, 50)
        Dim aCircle As New System.Drawing.Drawing2D.GraphicsPath
        aCircle.AddEllipse(New System.Drawing.RectangleF(0, 0, 50, 50))
        Button1.Region = New Region(aCircle)

執行結果

 

參考 

http://www.blueshop.com.tw/board/show.asp?subcde=BRD20090316190923MFS&fumcde=