答案 0 :(得分:2)
您需要做的是拥有一个变量,其中包含已选中复选框的计数:
Private cbChecked As Integer = 0
然后,为所有Checkboxes CheckedChanged
事件创建一个处理程序,如下所示:
Private Sub CheckBoxes_CheckedChanged(sender As Object, e As EventArgs)
Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged ...
Dim cb As CheckBox = TryCast(sender, CheckBox)
If cb.Checked Then
cbChecked += 1
Else
cbChecked -= 1
End If
If cbChecked = 5 Then
For Each cbx As CheckBox In Me.Controls.OfType(Of CheckBox)
If Not cbx.Checked Then
cbx.Enabled = False
End If
Next
Else
For Each cbx As CheckBox In Me.Controls.OfType(Of CheckBox)
cbx.Enabled = True
Next
End If
End Sub
这可以让你知道该怎么做。