标题:checkbox的问题
只看楼主
chen3bing
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:507
专家分:104
注 册:2008-11-12
结帖率:91.22%
已结贴  问题点数:10 回复次数:2 
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
可是有个问题,点的时候有可能一个也不选。
请问高手,如何解决?谢谢!
搜索更多相关主题的帖子: checkbox Case Text1 False Index 
2020-02-27 14:01
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4912
专家分:29900
注 册:2008-10-15
得分:5 
Dim ck As CheckBox                      '定义变量
Static chv As Boolean
If chv Then Exit Sub                    '如果是因代码引发本事件,则忽略
chv = True                              '设置当前操作标志
Check1(Index).Value = 1                 '不能取消选择
    For Each ck In Check1               '循环开始
        If ck.Index <> Index Then       '是否是当前控件
            ck.Value = 0                '不是,则设置未选择
        End If
    Next
chv = False                             '清除操作标志


[此贴子已经被作者于2020-2-27 17:36编辑过]


授人于鱼,不如授人于渔
早已停用QQ了
2020-02-27 17:26
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4912
专家分:29900
注 册:2008-10-15
得分:5 
Static chv As Boolean
If chv Then Exit Sub                    '如果是因代码引发本事件,则忽略
chv = True                              '设置当前操作标志
................
chv = False                             '清除操作标志

建议另一个部分也加上这节代码,防止意外导致堆栈溢出,

授人于鱼,不如授人于渔
早已停用QQ了
2020-02-27 18:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-499428-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.094567 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved