(已解决)请教个复选框的问题
本帖最后由 mo_shaojie 于 2011-4-30 12:21 编辑请教高手们支下招,看下我以下的代码错在哪里?#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $Checkbox
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Checkbox = GUICtrlCreateCheckbox("Checkbox1", 48, 32, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox2", 48, 64, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox3", 48, 104, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox4", 48, 136, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox5", 48, 176, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox6", 48, 216, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox7", 48, 256, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox8", 48, 296, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox9", 48, 336, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox10", 48, 376, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox11", 48, 416, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox12", 216, 32, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox13", 216, 64, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox14", 216, 104, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox15", 216, 144, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox16", 216, 184, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox17", 216, 224, 97, 17)
$Checkbox = 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
现在的问题是,把全选和推荐都打上勾,出现选框选上是错的.应该怎样判断才能正确呢?分别打勾的话就没问题. 我刚试了下没有问题啊? 我刚试了下没有问题啊?
zcx880517 发表于 2011-4-25 08:43 http://www.autoitx.com/images/common/back.gif
你把全选和推荐两个都打上勾看看. 你的控件使用就不合理吧!为什么不用 GUICtrlCreateRadio 单选框。 你的控件使用就不合理吧!为什么不用 GUICtrlCreateRadio 单选框。
水木子 发表于 2011-4-25 09:04 http://www.autoitx.com/images/common/back.gif
哈,我知道啊,但是想用$checkbox试下的效果.有什么方法解决了. 这哪有既用全选又用推荐的? 回复 5# mo_shaojie
这样是不是更合理一些呢?
Dim $Checkbox
GUICreate("Form1", 600, 450)
$Checkbox = GUICtrlCreateCheckbox("Checkbox1", 48, 32, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox2", 48, 64, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox3", 48, 104, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox4", 48, 136, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox5", 48, 176, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox6", 48, 216, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox7", 48, 256, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox8", 48, 296, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox9", 48, 336, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox10", 48, 376, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox11", 48, 416, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox12", 216, 32, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox13", 216, 64, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox14", 216, 104, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox15", 216, 144, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox16", 216, 184, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox17", 216, 224, 97, 17)
$Checkbox = 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 本帖最后由 netegg 于 2011-4-25 12:47 编辑
逻辑设计有问题,你选了一个后再选另一个时按你的逻辑是取反,自然是不能都选上,你的逻辑基本上是反选的逻辑 case $checkbox19
For $i = 1 To 18
If GUICtrlRead($Checkbox[$i]) = 4 then
GUICtrlSetState($Checkbox[$i], $GUI_CHECKED )
EndIf
Next
EndSwitch case $checkbox19
For $i = 1 To 18
If GUICtrlRead($Checkbox[$i]) = 4 then
...
netegg 发表于 2011-4-25 12:45 http://www.autoitx.com/images/common/back.gif
对了.就是逻辑的问题了.我测试下. 还是不行的,单个把勾去掉了,选上的不会去掉勾. 回复mo_shaojie
这样是不是更合理一些呢?
水木子 发表于 2011-4-25 11:50 http://www.autoitx.com/images/common/back.gif
单个把勾去掉的话,选上了的勾不会清掉. 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
回复 13# netegg
蛋蛋的代码可以这样简化一下。Case $Checkbox19
For $i = 1 To 18
GUICtrlSetState($Checkbox[$i], GUICtrlRead($Checkbox19))
Next 回复 14# 水木子
{:face (239):}光想着楼主那个循环了,没注意看,嘻嘻