BP.*_*BP. 1 .net vb.net winforms
我有一个WinForms应用程序(VS 2008,.NET 3.5),它有一个带有两个不同组框的表单,每个组框内部是不同的单选按钮组.当我运行应用程序时,第一个组框自动选中其中的第一个单选按钮,第二个组框默认没有选中单选按钮.
我查看了单选按钮和组合框的所有属性,但无法弄清楚两者之间的区别.我希望两个分组框在首次打开表单时取消选择所有单选按钮.
此外,我查看了Designer.vb文件中的表单,并且在那里找不到任何异常.
Set all the buttons' AutoCheck property to False. You'll now have to write a Click handler for them to set their Checked property. A sample handler that takes care of two of them:
Private Sub RadioButton_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles RadioButton1.Click, RadioButton2.Click
Dim button As RadioButton = DirectCast(sender, RadioButton)
RadioButton1.Checked = button is RadioButton1
RadioButton2.Checked = button Is RadioButton2
End Sub
Run Code Online (Sandbox Code Playgroud)
我也遇到过这个问题.我只是在Form_Shown事件中手动将所有RadioButton对象设置为.Checked = False.请注意,它必须在 Form_Load事件之后,否则将无法工作,并且RadioButton将设置为默认值.
为什么?我不知道.也许是VB.NET中的一个错误.