【VB.net】丸いボタン、角の丸いボタンを作る

1.CircleButtonというプロジェクトを作る
2.プロジェクトにクラスファイルを追加する
3.クラスファイルにコードを書く
4.一度コンパイル(ビルド)する
5.ツールボックスから対応したコントロールをフォームに張り付ける
6.RoundButtonはプロパティRoundで丸みを調整できる

※貼り付けたコントロールのFlatAppearaanceのBorderSizeを0、FlatStyleをFlatにして下さい

以下クラスファイルに書くコード

EllipseButton.vb

Imports System.Windows.Forms
Imports System.Drawing.Drawing2D

Public Class EllipseButton
    Inherits Button

    Protected Overrides Sub OnPaint(pevent As PaintEventArgs)
        Dim gp As GraphicsPath = New GraphicsPath
        gp.StartFigure()
        gp.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height)
        gp.CloseFigure()
        Me.Region = New System.Drawing.Region(gp)
        MyBase.OnPaint(pevent)
    End Sub
End Class

RoundButton.vb

Imports System.Windows.Forms
Imports System.Drawing.Drawing2D

Public Class RoundButton
    Inherits Button

    Protected Overrides Sub OnPaint(pevent As PaintEventArgs)
        Dim gp As GraphicsPath = New GraphicsPath
        Dim r As Single = pr
        Dim x As Single = 0.0F
        Dim y As Single = 0.0F
        Dim w As Single = ClientSize.Width
        Dim h As Single = ClientSize.Height
        gp.StartFigure()
        gp.AddArc(x, y, r, r, 180.0F, 90.0F)
        gp.AddArc(w - r, y, r, r, 270.0F, 90.0F)
        gp.AddArc(w - r, h - r, r, r, 0.0F, 90.0F)
        gp.AddArc(x, h - r, r, r, 90.0F, 90.0F)
        gp.CloseFigure()
        Me.Region = New System.Drawing.Region(gp)
        MyBase.OnPaint(pevent)
    End Sub

    Private pr = 50
    Public Property Round() As Single
        Get
            Return pr
        End Get
        Set(value As Single)
            pr = value
        End Set
    End Property

End Class

SideRoundButton.vb

Imports System.Windows.Forms
Imports System.Drawing.Drawing2D

Public Class SideRoundButton
    Inherits Button

    Protected Overrides Sub OnPaint(pevent As PaintEventArgs)
        Dim gp As GraphicsPath = New GraphicsPath
        Dim x As Single = 0.0F
        Dim y As Single = 0.0F
        Dim w As Single = ClientSize.Width
        Dim h As Single = ClientSize.Height
        gp.StartFigure()
        gp.AddArc(x, y, h, h, 90.0F, 180.0F)
        gp.AddArc(w - h, y, h, h, 270.0F, 180.0F)
        gp.CloseFigure()
        Me.Region = New System.Drawing.Region(gp)
        MyBase.OnPaint(pevent)
    End Sub
End Class