level 9
把checkbox塞进一个list里,checked事件里判断当前被"打勾"的是哪个checkbox,同时把其他的checkbox都"取消打勾",就结了。
2018年05月15日 06点05分
2
level 1
忘了说了。这个是8组。一组两个CheckBox。我想问的是简便方法。用CheckBox或RadioButton,我知道怎么弄。我只是觉得那样太麻烦了。
2018年05月16日 01点05分
4
level 1
现在已经基本实现,但是问题是勾选了一个之后,另一个就勾选不了。只能先把勾选去掉才能勾选另一个。我想要的效果是,勾选另一个后,前一个就自动取消了。
代码:
Private Sub GN_CHK_Divout_CheckedChanged(sender As Object, e As EventArgs) Handles GN_CHK_Divout0.CheckedChanged, GN_CHK_Divout1.CheckedChanged, GN_CHK_Divout2.CheckedChanged, GN_CHK_Divout3.CheckedChanged, GN_CHK_Divout4.CheckedChanged, GN_CHK_Divout5.CheckedChanged, GN_CHK_Divout6.CheckedChanged, GN_CHK_Divout7.CheckedChanged, GN_CHK_Divout00.CheckedChanged, GN_CHK_Divout01.CheckedChanged, GN_CHK_Divout02.CheckedChanged, GN_CHK_Divout03.CheckedChanged, GN_CHK_Divout04.CheckedChanged, GN_CHK_Divout05.CheckedChanged, GN_CHK_Divout06.CheckedChanged, GN_CHK_Divout07.CheckedChanged
Dim currentCKB As CheckBox
For i = 0 To 7
For Each control As Control In GN_GBoxDivOutput.Controls
If (control.Name = "GN_CHK_Divout" & i) Then
If CType(control, System.Windows.Forms.CheckBox).Checked = True Then
For Each control1 As Control In GN_GBoxDivOutput.Controls
If (control1.Name = "GN_CHK_Divout0" & i) Then
currentCKB = control1
currentCKB.Checked = False
End If
Next
End If
End If
If (control.Name = "GN_CHK_Divout0" & i) Then
If CType(control, System.Windows.Forms.CheckBox).Checked = True Then
For Each control1 As Control In GN_GBoxDivOutput.Controls
If (control1.Name = "GN_CHK_Divout" & i) Then
currentCKB = control1
currentCKB.Checked = False
End If
Next
End If
End If
Next
Next
End Sub
2018年05月16日 06点05分
5
你这是逻辑错误了。如果前面的被选中,你再选另一个时(此时实际已经选中了),会激发CheckedChanged,而在这个事件中,会把选中状态清除掉。
2018年05月16日 09点05分
level 1
使用Click事件,尽量扁平化,减少嵌套。
Static Dim lt As New Dictionary(Of String, CheckBox) From
{
{"GN_CHK_Divout0", GN_CHK_Divout00},
{"GN_CHK_Divout1", GN_CHK_Divout01},
{"GN_CHK_Divout2", GN_CHK_Divout02},
{"GN_CHK_Divout3", GN_CHK_Divout03},
{"GN_CHK_Divout4", GN_CHK_Divout04},
{"GN_CHK_Divout5", GN_CHK_Divout05},
{"GN_CHK_Divout6", GN_CHK_Divout06},
{"GN_CHK_Divout7", GN_CHK_Divout07},
{"GN_CHK_Divout00", GN_CHK_Divout0},
{"GN_CHK_Divout01", GN_CHK_Divout1},
{"GN_CHK_Divout02", GN_CHK_Divout2},
{"GN_CHK_Divout03", GN_CHK_Divout3},
{"GN_CHK_Divout04", GN_CHK_Divout4},
{"GN_CHK_Divout05", GN_CHK_Divout5},
{"GN_CHK_Divout06", GN_CHK_Divout6},
{"GN_CHK_Divout07", GN_CHK_Divout7}
}
Dim name = CType(sender, CheckBox).Name
lt(name).Checked = False
2018年05月16日 09点05分
7
谢谢,这个要点两下是怎么回事。
2018年05月17日 02点05分
@蓝梦妖蝶 我这个只要点一下,已经Debug过,楼上那要在上面有解释。
2018年05月17日 03点05分
@蓝梦妖蝶 要用Click事件,如果用CheckedChanged事件会要点两下。因为第一次激活时,把互斥的复选框取消后又会激发一下CheckedChanged事件,这个事件会把选中的状态取消掉。
2018年05月17日 04点05分