|  |  | 
              
              | 
                  | Title | Make a ColorRadioButton control that changes color when checked and unchecked in VB .NET | 
|---|
 | Description | This example shows how to make a ColorRadioButton control that changes color when checked and unchecked in VB .NET. | 
|---|
 | Keywords | RadioButton, ColorRadioButton, control, VB.NET | 
|---|
 | Categories | Controls, VB.NET | 
|---|
 |  | 
 |  | The control inherits from the RadioButton class and adds CheckedColor and UncheckedColor properties. When the user changes one of these values, or when the control's CheckedChanged event handler fires, the code calls subroutine SetColor. That routine sets the control's ForeColor property to either CheckedColor or UncheckedColor depending on whether it is currently checked. |  | 
 |  
                | <ToolboxBitmap(GetType(ColoredRadioButton), _
    "color_btn_tool.bmp")> _
Public Class ColoredRadioButton
    Inherits RadioButton
    Private m_CheckedColor As Color
    Public Property CheckedColor() As Color
        Get
            Return m_CheckedColor
        End Get
        Set(ByVal Value As Color)
            m_CheckedColor = Value
            SetColor()
        End Set
    End Property
    Private m_UncheckedColor As Color
    Public Property UncheckedColor() As Color
        Get
            Return m_UncheckedColor
        End Get
        Set(ByVal Value As Color)
            m_UncheckedColor = Value
            SetColor()
        End Set
    End Property
    Private Sub ColoredRadioButton_CheckedChanged(ByVal _
        sender As Object, ByVal e As System.EventArgs) _
        Handles MyBase.CheckedChanged
        SetColor()
    End Sub
    Private Sub SetColor()
        If Me.Checked Then
            Me.ForeColor = m_CheckedColor
        Else
            Me.ForeColor = m_UncheckedColor
        End If
    End Sub
End Class |  |  |  |   |  |  |  |  |