How do I change the color of a small circle (dot) contained within the radio button to be red in Winform Application use VB.NET or C#?
Regard & Thanks, Dewi
==========================================================
I will share, may be useful to others. This program works.
Imports System.Drawing.Drawing2D
Public Class Form1
Public Class MyRadioButton
Inherits RadioButton
Private m_OnColor As Color
Private m_OffColor As Color
Public Sub New(ByVal On_Color As Color, ByVal Off_Color As Color)
m_OnColor = On_Color
m_OffColor = Off_Color
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
BackColor = Color.Transparent
End Sub
Public Property OnColor() As Color
Get
Return m_OnColor
End Get
Set(ByVal value As Color)
m_OnColor = value
End Set
End Property
Public Property OffColor() As Color
Get
Return m_OffColor
End Get
Set(ByVal value As Color)
m_OffColor = value
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Dim g As Graphics = e.Graphics
g.SmoothingMode = SmoothingMode.AntiAlias
Dim dotDiameter As Integer = ClientRectangle.Height - 17
Dim innerRect As New RectangleF(1.8F, 7.8F, dotDiameter, dotDiameter)
If Me.Checked Then
g.FillEllipse(New SolidBrush(OnColor), innerRect)
Else
g.FillEllipse(New SolidBrush(OffColor), innerRect)
End If
g.DrawString(Text, Font, New SolidBrush(ForeColor), dotDiameter + 17, 1)
End Sub
End Class
Dim objRadio As New MyRadioButton(Color.Blue, Color.Red)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
objRadio.Location = New Point(100, 100)
objRadio.Visible = True
Me.Controls.Add(objRadio)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If objRadio.Checked Then
objRadio.Checked = False
Else
objRadio.Checked = True
End If
End Sub
End Class
ControlPaint.DrawRadioButton(e.Graphics, rect, ButtonState.Checked);
. How would you change this to draw a red circle? – Jeffjeffcoat