Change the color of a small circle (dot) contained within the radio button to be red?(将单选按钮中包含的小圆圈(点)的颜色更改为红色?)
问题描述
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
Here's a winforms example of an owner drawn listbox simulating a list of radiobuttons that you could use for what you want.
Edit: Here is a more in-depth Winforms custom control example.
这篇关于将单选按钮中包含的小圆圈(点)的颜色更改为红色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将单选按钮中包含的小圆圈(点)的颜色更改为红色?
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01