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

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

问题描述

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天全站免登陆