vb.net 默认禁用单选按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19379561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:29:20  来源:igfitidea点击:

Disable radio buttons by default

vb.netwinforms

提问by user1532468

I am trying to find a way to make radio buttons disabled by default. I have managed to disable them inside my event handler for CheckedChangedbut that only works when action is taken by the user. How do I disable the control by default?

我试图找到一种方法来默认禁用单选按钮。我已经设法在我的事件处理程序中禁用它们,CheckedChanged但这仅在用户采取行动时才有效。如何默认禁用控件?

Private Sub rdoCustomer_CheckedChanged(ByVal sender As Object, 
                                       ByVal e As EventArgs) _    
    Handles rdoCustomer.CheckChanged, rdoDepartment.CheckedChanged

    rdoCustomer.Enabled = False
    rdoCustomer.Checked = True
    rdoDepartment.Enabled = False
End Sub

回答by varocarbas

To set anything "by default", just write it in the Form Load Event. Sample:

要“默认”设置任何内容,只需将其写入Form Load Event. 样本:

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    rdoCustomer.Enabled = False
    rdoCustomer.Checked = False
    rdoDepartment.Enabled = False
    rdoDepartment.Checked = False
End Sub

Or, alternatively, via properties of the given control(s) in "Design View". All this by assuming that the controls weren't created at runtime (in that case, right after being created).

或者,或者,通过“设计视图”中给定控件的属性。所有这一切都是假设控件不是在运行时创建的(在这种情况下,是在创建之后)。