Public Class ColorPaletteButton
    ' color...
    Public Color As Color = Color.Black
    Public Rectangle As Rectangle
    Public ButtonAssignment As ButtonAssignments = ButtonAssignments.None

    ' enums...
    Public Enum ButtonAssignments As Integer
        None = 0
        LeftButton = 1
        RightButton = 2
    End Enum

    ' constructor...
    Public Sub New(ByVal newColor As Color)
        Color = newColor
    End Sub

    ' SetPosition - move the button to the given position...
    Public Sub SetPosition(ByVal x As Integer, ByVal y As Integer, _
                        ByVal buttonSize As Integer)

        ' update the members...
        Rectangle = New Rectangle(x, y, buttonSize, buttonSize)

    End Sub

    ' Draw - draw the button...
    Public Sub Draw(ByVal graphics As Graphics)

        ' draw the color block...
        Dim brush As New SolidBrush(Color)
        graphics.FillRectangle(brush, Rectangle)

        ' draw an "edge" around the control...
        Dim pen As New Pen(Color.Black)
        graphics.DrawRectangle(pen, Rectangle)

        ' are we selected?
        If ButtonAssignment <> ButtonAssignments.None Then

            ' create a font...
            Dim font As New Font("verdana", 8, FontStyle.Bold)

            ' what text do we use?
            Dim buttonText As String = "L"
            If ButtonAssignment = ButtonAssignments.RightButton Then _
                              buttonText = "R"

            ' what brush do we want...
            Dim fontBrush As SolidBrush
            If Color.R < 100 Or Color.B < 100 Or Color.G < 100 Then
                fontBrush = New SolidBrush(Color.White)
            Else
                fontBrush = New SolidBrush(Color.Black)
            End If

            ' draw some text...
            graphics.DrawString(buttonText, font, fontBrush, _
                  Rectangle.Left, Rectangle.Top)

        End If

    End Sub
End Class
