使用户检查 RadioButton 而不禁用它 [英] Void user check RadioButton without disabling it

查看:34
本文介绍了使用户检查 RadioButton 而不禁用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 GroupBox 中有四个 RadioButton,我需要禁止用户更改它的状态但不禁用控件,因为我需要它们看起来没有禁用(灰色).我正在通过代码控制它们.我试图将 AutoClick 更改为 false,但是当我通过代码更改它们时,我检查了不止一个 RadioButton.

I have four RadioButtons inside a GroupBox and I need to forbid user to change it status but without disabling the control because I need that they look NOT disabled(grayed). I'm controlling them from code. I tried to change AutoClick to false but I get more than one RadioButton checked when I change them by code.

当然,我每次都可以更改所有 RadioButtons 状态,但这看起来有点乱.

Of course I can change all the RadioButtons status every time but that looks a bit messy.

推荐答案

您可以为此使用继承的类.

You can use an inherited class for this.

将 IsReadOnly 标记为 true 以禁用点击.

Mark IsReadOnly to true to disable the click.

Class ReadOnlyRadioButton
    Inherits System.Windows.Forms.RadioButton

    Private mRo as Boolean

    Public Property IsReadOnly As Boolean
        Get
            Return mRo 
        End Get
        Set(ByVal value as String)
            mRo = value
        End Set
    End Property

    Protected Overrides Sub OnClick(ByVal e As EventArgs)
        If Not Me.IsReadOnly Then
            MyBase.OnClick(e)
        End If

    End Sub
End Class

这篇关于使用户检查 RadioButton 而不禁用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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