找回密码
 加入
搜索
查看: 15634|回复: 43

[AU3基础] (已解决)请教个复选框的问题

 火.. [复制链接]
发表于 2011-4-24 23:39:13 | 显示全部楼层 |阅读模式
本帖最后由 mo_shaojie 于 2011-4-30 12:21 编辑

请教高手们支下招,看下我以下的代码错在哪里?
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $Checkbox[19]
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Checkbox[1] = GUICtrlCreateCheckbox("Checkbox1", 48, 32, 97, 17)
$Checkbox[2] = GUICtrlCreateCheckbox("Checkbox2", 48, 64, 97, 17)
$Checkbox[3] = GUICtrlCreateCheckbox("Checkbox3", 48, 104, 97, 17)
$Checkbox[4] = GUICtrlCreateCheckbox("Checkbox4", 48, 136, 97, 17)
$Checkbox[5] = GUICtrlCreateCheckbox("Checkbox5", 48, 176, 97, 17)
$Checkbox[6] = GUICtrlCreateCheckbox("Checkbox6", 48, 216, 97, 17)
$Checkbox[7] = GUICtrlCreateCheckbox("Checkbox7", 48, 256, 97, 17)
$Checkbox[8] = GUICtrlCreateCheckbox("Checkbox8", 48, 296, 97, 17)
$Checkbox[9] = GUICtrlCreateCheckbox("Checkbox9", 48, 336, 97, 17)
$Checkbox[10] = GUICtrlCreateCheckbox("Checkbox10", 48, 376, 97, 17)
$Checkbox[11] = GUICtrlCreateCheckbox("Checkbox11", 48, 416, 97, 17)
$Checkbox[12] = GUICtrlCreateCheckbox("Checkbox12", 216, 32, 97, 17)
$Checkbox[13] = GUICtrlCreateCheckbox("Checkbox13", 216, 64, 97, 17)
$Checkbox[14] = GUICtrlCreateCheckbox("Checkbox14", 216, 104, 97, 17)
$Checkbox[15] = GUICtrlCreateCheckbox("Checkbox15", 216, 144, 97, 17)
$Checkbox[16] = GUICtrlCreateCheckbox("Checkbox16", 216, 184, 97, 17)
$Checkbox[17] = GUICtrlCreateCheckbox("Checkbox17", 216, 224, 97, 17)
$Checkbox[18] = GUICtrlCreateCheckbox("Checkbox18", 216, 264, 97, 17)
$Checkbox19 = GUICtrlCreateCheckbox("全选", 392, 312, 97, 17)
$Checkbox20 = GUICtrlCreateCheckbox("推荐", 392, 352, 97, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
         case $checkbox20
        For $i = 10 To 13
                                        If GUICtrlRead($Checkbox[$i]) = 1 then
                                        GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED )
                                        Elseif GUICtrlRead($Checkbox[$i]) = 4 then
                                   GUICtrlSetState($checkbox[$i],$GUI_CHECKED )
                                   EndIf
                           Next
        case $checkbox19
        For $i = 1 To 18
                                        If GUICtrlRead($Checkbox[$i]) = 1 then
                                        GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED )
                                        Elseif GUICtrlRead($Checkbox[$i]) = 4 then
                                   GUICtrlSetState($checkbox[$i],$GUI_CHECKED )
                                   EndIf
                           Next

        EndSwitch
WEnd
现在的问题是,把全选和推荐都打上勾,出现选框选上是错的.应该怎样判断才能正确呢?分别打勾的话就没问题.
发表于 2011-4-25 08:43:21 | 显示全部楼层
我刚试了下没有问题啊?
 楼主| 发表于 2011-4-25 08:53:07 | 显示全部楼层
我刚试了下没有问题啊?
zcx880517 发表于 2011-4-25 08:43


你把全选和推荐两个都打上勾看看.
发表于 2011-4-25 09:04:51 | 显示全部楼层
你的控件使用就不合理吧!为什么不用 GUICtrlCreateRadio 单选框。
 楼主| 发表于 2011-4-25 09:24:43 | 显示全部楼层
你的控件使用就不合理吧!为什么不用 GUICtrlCreateRadio 单选框。
水木子 发表于 2011-4-25 09:04


哈,我知道啊,但是想用$checkbox试下的效果.有什么方法解决了.
发表于 2011-4-25 11:06:29 | 显示全部楼层
这哪有既用全选又用推荐的?
发表于 2011-4-25 11:50:25 | 显示全部楼层
回复 5# mo_shaojie

这样是不是更合理一些呢?
Dim $Checkbox[19]
GUICreate("Form1", 600, 450)
$Checkbox[1] = GUICtrlCreateCheckbox("Checkbox1", 48, 32, 97, 17)
$Checkbox[2] = GUICtrlCreateCheckbox("Checkbox2", 48, 64, 97, 17)
$Checkbox[3] = GUICtrlCreateCheckbox("Checkbox3", 48, 104, 97, 17)
$Checkbox[4] = GUICtrlCreateCheckbox("Checkbox4", 48, 136, 97, 17)
$Checkbox[5] = GUICtrlCreateCheckbox("Checkbox5", 48, 176, 97, 17)
$Checkbox[6] = GUICtrlCreateCheckbox("Checkbox6", 48, 216, 97, 17)
$Checkbox[7] = GUICtrlCreateCheckbox("Checkbox7", 48, 256, 97, 17)
$Checkbox[8] = GUICtrlCreateCheckbox("Checkbox8", 48, 296, 97, 17)
$Checkbox[9] = GUICtrlCreateCheckbox("Checkbox9", 48, 336, 97, 17)
$Checkbox[10] = GUICtrlCreateCheckbox("Checkbox10", 48, 376, 97, 17)
$Checkbox[11] = GUICtrlCreateCheckbox("Checkbox11", 48, 416, 97, 17)
$Checkbox[12] = GUICtrlCreateCheckbox("Checkbox12", 216, 32, 97, 17)
$Checkbox[13] = GUICtrlCreateCheckbox("Checkbox13", 216, 64, 97, 17)
$Checkbox[14] = GUICtrlCreateCheckbox("Checkbox14", 216, 104, 97, 17)
$Checkbox[15] = GUICtrlCreateCheckbox("Checkbox15", 216, 144, 97, 17)
$Checkbox[16] = GUICtrlCreateCheckbox("Checkbox16", 216, 184, 97, 17)
$Checkbox[17] = GUICtrlCreateCheckbox("Checkbox17", 216, 224, 97, 17)
$Checkbox[18] = GUICtrlCreateCheckbox("Checkbox18", 216, 264, 97, 17)
$Checkbox19 = GUICtrlCreateRadio("全选", 392, 312, 97, 17)
$Checkbox20 = GUICtrlCreateRadio("推荐", 392, 352, 97, 17)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Checkbox19
                        For $i = 1 To 18
                                GUICtrlSetState($Checkbox[$i], 1)
                        Next
                Case $Checkbox20
                        For $i = 1 To 18
                                Switch $i
                                        Case 10 To 13
                                                GUICtrlSetState($Checkbox[$i], 1)
                                        Case Else
                                                GUICtrlSetState($Checkbox[$i], 4)
                                EndSwitch
                        Next
        EndSwitch
WEnd
发表于 2011-4-25 12:42:38 | 显示全部楼层
本帖最后由 netegg 于 2011-4-25 12:47 编辑

逻辑设计有问题,你选了一个后再选另一个时按你的逻辑是取反,自然是不能都选上,你的逻辑基本上是反选的逻辑
发表于 2011-4-25 12:45:45 | 显示全部楼层
case $checkbox19
        For $i = 1 To 18
             If GUICtrlRead($Checkbox[$i]) = 4 then
                 GUICtrlSetState($Checkbox[$i], $GUI_CHECKED )
              EndIf
        Next
EndSwitch
 楼主| 发表于 2011-4-25 13:28:17 | 显示全部楼层
case $checkbox19
        For $i = 1 To 18
             If GUICtrlRead($Checkbox[$i]) = 4 then
    ...
netegg 发表于 2011-4-25 12:45

对了.就是逻辑的问题了.我测试下.
 楼主| 发表于 2011-4-25 13:39:48 | 显示全部楼层
还是不行的,单个把勾去掉了,选上的不会去掉勾.
 楼主| 发表于 2011-4-25 13:40:35 | 显示全部楼层
回复  mo_shaojie

这样是不是更合理一些呢?
水木子 发表于 2011-4-25 11:50


单个把勾去掉的话,选上了的勾不会清掉.
发表于 2011-4-25 15:25:02 | 显示全部楼层
                Case $Checkbox19
                        If GUICtrlRead($Checkbox19) = 4 Then
                                For $i = 1 To 18
                                        GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED)
                                Next
                        Else
                                For $i = 1 To 18
                                        GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
                                Next
                        EndIf
发表于 2011-4-25 15:34:37 | 显示全部楼层
回复 13# netegg

蛋蛋的代码可以这样简化一下。
Case $Checkbox19
        For $i = 1 To 18
                GUICtrlSetState($Checkbox[$i], GUICtrlRead($Checkbox19))
        Next
发表于 2011-4-25 15:42:24 | 显示全部楼层
回复 14# 水木子


    光想着楼主那个循环了,没注意看,嘻嘻
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-16 22:00 , Processed in 0.077942 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表