更改包含的单选按钮中的一个小圆圈(点)的颜色是红色? [英] Change the color of a small circle (dot) contained within the radio button to be red?

查看:1249
本文介绍了更改包含的单选按钮中的一个小圆圈(点)的颜色是红色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改包含的单选按钮中的一个小圆圈(点)的颜色是红色的WinForm的应用程序中使用VB.NET或C#?



&方面放大器;谢谢,
黛维



============================ ==============================结果
我将分享,可能是对别人有用。这个程序的工作原理。

 进口System.Drawing.Drawing2D 

类公共Form1的

酒店的公共类MyRadioButton
继承单选

私人m_OnColor至于颜色
私人m_OffColor至于颜色

的Public Sub New(BYVAL On_Color颜色,BYVAL Off_Color作为彩色)
m_OnColor = On_Color
m_OffColor = Off_Color
的SetStyle(ControlStyles.SupportsTransparentBackColor,真)
=背景色Color.Transparent
端子

酒店的公共属性的OnColor()作为颜色
得到
返回m_OnColor
端获取
组(BYVAL值作为颜色)
m_OnColor =价值
端设置
高端物业
$ b)$ b公共财产OffColor(如颜色
得到
返回m_OffColor
端获取
组(BYVAL值作为彩色)
m_OffColor =价值
端设置
高端物业

受保护的覆盖子的OnPaint(BYVALË作为PaintEventArgs)
MyBase.OnPaint(五)

尺寸摹作为图形= e.Graphics
g.Smoothi​​ngMode = Smoothi​​ngMode.AntiAlias​​

昏暗dotDiameter为整数= ClientRectangle.Height - 17
昏暗innerRect作为新的RectangleF(1.8F,7.8F,dotDiameter,dotDiameter)

。如果Me.Checked然后
g.FillEllipse(新SolidBrush(的OnColor),innerRect)
,否则
g.FillEllipse(新SolidBrush(OffColor),innerRect)
端如果

g.DrawString(文字,字体,新SolidBrush(前景色),dotDiameter + 17,1)
结束小组

端类


尺寸objRadio作为新MyRadioButton(Color.Blue,Color.Red)

私人小组Form1_Load的( BYVAL发件人为System.Object的,BYVAL E上System.EventArgs)把手MyBase.Load
objRadio.Location =新点(100,100)
objRadio.Visible = TRUE
Me.Controls。添加(objRadio)
端子

私人小组的button1_Click(BYVAL发件人为System.Object的,BYVAL E上System.EventArgs)把手Button1.Click
如果objRadio.Checked然后
objRadio.Checked =假
,否则
objRadio.Checked = TRUE
端如果
端子


端类


解决方案

这里的所有者列表框绘制模拟,你可以使用你的单选按钮列表的例子的WinForms 。希望



编辑:这里是一个更深入的WinForms自定义控件的例子。


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.

这篇关于更改包含的单选按钮中的一个小圆圈(点)的颜色是红色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆