
' リスト7：DrawButtonのカスタムプロパティ
Private mChecked As Boolean
Private mMultiLine As Boolean
Private mTextAlign As ContentAlignment
Private mMutilLineText() As String
Private mMyButtonState As ButtonState

Public Sub New()
    MyBase.New()

    Me.Size = New Size(75, 23)
    Me.Text = Me.ToString
    Me.TextAlign = ContentAlignment.MiddleCenter
    Me.ResizeRedraw = True
    mMyButtonState = ButtonState.Normal
End Sub

<Category("DotNetMagazine")> _
Public Property MyButtonState() As ButtonState
    Get
        Return mMyButtonState
    End Get
    Set(ByVal Value As ButtonState)
        mMyButtonState = Value
        Me.Invalidate()
    End Set
End Property

<Category("DotNetMagazine")> _
Public Property MutilLineText() As String()
    Get
        Return mMutilLineText
    End Get
    Set(ByVal Value As String())
        Dim s As String
        mMutilLineText = Value

         ' マルチラインを設定していない場合は処理を終了する
        If mMultiLine = False Then
            Exit Property
        End If

        For Each line As String In mMutilLineText
            s += line & vbCrLf
        Next

        Me.Text = s
    End Set
End Property

<Category("DotNetMagazine")> _
Public Property MultiLine() As Boolean
    Get
        Return mMultiLine
    End Get
    Set(ByVal Value As Boolean)
        mMultiLine = Value
        If mMultiLine Then
            If Not IsNothing(mMutilLineText) Then
                MutilLineText = mMutilLineText
            End If
        End If
        Me.Invalidate()
    End Set
End Property

<Category("DotNetMagazine")> _
Public Property TextAlign() As ContentAlignment
    Get
        Return mTextAlign
    End Get
    Set(ByVal Value As ContentAlignment)
        mTextAlign = Value
        Me.Invalidate()
    End Set
End Property