checkbox的问题
界面如图。共有8个checkbox控件,上面四个和下面四个不一样。
下面四个可以都不选,但最多选一个。这四个我写好了。
上面四个只能选一个,而且必须选一个。
因为下面用的复选框,所以上面也用复选框实现,否则不协调。
上面四个的代码如下:
Private Sub Check3_Click(Index As Integer)
Dim ck As CheckBox '定义变量
If Check3(Index).Value = 1 Then '当前是否选择
For Each ck In Check3 '循环开始
If ck.Index <> Index Then '是否是当前控件
ck.Value = 0 '不是,则设置未选择
Else
ck.Value = 1
End If
Next
Select Case Index
Case 0
Text1.ForeColor = vbBlue
Text1.Locked = False
Text3.ForeColor = vbBlack
Text3.Locked = True
Text4.ForeColor = vbBlack
Text4.Locked = True
Text5.ForeColor = vbBlack
Text5.Locked = True
Case 1
Text3.ForeColor = vbBlue
Text3.Locked = False
Text1.ForeColor = vbBlack
Text1.Locked = True
Text4.ForeColor = vbBlack
Text4.Locked = True
Text5.ForeColor = vbBlack
Text5.Locked = True
Case 2
Text4.ForeColor = vbBlue
Text4.Locked = False
Text1.ForeColor = vbBlack
Text1.Locked = True
Text3.ForeColor = vbBlack
Text3.Locked = True
Text5.ForeColor = vbBlack
Text5.Locked = True
Case 3
Text5.ForeColor = vbBlue
Text5.Locked = False
Text1.ForeColor = vbBlack
Text1.Locked = True
Text4.ForeColor = vbBlack
Text4.Locked = True
Text3.ForeColor = vbBlack
Text3.Locked = True
End Select
End If
End Sub
可是有个问题,点的时候有可能一个也不选。
请问高手,如何解决?谢谢!