Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a ColorRadioButton control that changes color when checked and unchecked in VB .NET
DescriptionThis example shows how to make a ColorRadioButton control that changes color when checked and unchecked in VB .NET.
KeywordsRadioButton, ColorRadioButton, control, VB.NET
CategoriesControls, 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated