找回密码
 加入
搜索
查看: 1349|回复: 8

For $i=3 To 11

[复制链接]
发表于 2009-7-23 09:27:38 | 显示全部楼层 |阅读模式
本帖最后由 chenjt819 于 2009-7-23 12:48 编辑

#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("全选\反选", 261, 251, 340, 162)
$Checkbox1 = GUICtrlCreateCheckbox("1", 50, 50, 25, 17)
$Checkbox2 = GUICtrlCreateCheckbox("2", 120, 50, 25, 17)
$Checkbox3 = GUICtrlCreateCheckbox("3", 190, 50, 25, 17)
$Checkbox4 = GUICtrlCreateCheckbox("4", 50, 100, 25, 17)
$Checkbox5 = GUICtrlCreateCheckbox("5", 120, 100, 25, 17)
$Checkbox6 = GUICtrlCreateCheckbox("6", 190, 100, 25, 17)
$Checkbox7 = GUICtrlCreateCheckbox("7", 50, 150, 25, 17)
$Checkbox8 = GUICtrlCreateCheckbox("8", 120, 150, 25, 17)
$Checkbox9 = GUICtrlCreateCheckbox("9", 190, 150, 25, 17)
$Group1 = GUICtrlCreateGroup("10", 24, 24, 209, 169)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button = GUICtrlCreateButton("全选", 90, 210, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)

Dim $Checkbox,$B=True
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button
                 If $B=True Then
                         For $i=3 To 11
                         GUICtrlSetState($Checkbox&$i, $GUI_CHECKED)
                            GUICtrlSetData($Button,'反选')
                            Next
                          $B=False
               Else
                        For $i=3 To 11
                        If GUICtrlRead($Checkbox&$i)=1 then
                   GUICtrlSetState($Checkbox&$i, $GUI_UNCHECKED )
                         Elseif GUICtrlRead($Checkbox&$i)=4 then
                   GUICtrlSetState($Checkbox&$i, $GUI_CHECKED)
                   Endif
                           Next
                           $B=True
                           GUICtrlSetData($Button,'全选')
                           Endif
        EndSwitch
WEnd

为什么是 For $i=3 To 11  而不是 For $i=1 To 9

不是 Checkbox1 - Checkbox9  吗?
发表于 2009-7-23 09:37:23 | 显示全部楼层
这个我也不是很清楚,留名等高手解惑
发表于 2009-7-23 09:51:15 | 显示全部楼层
本帖最后由 milini 于 2009-7-23 09:55 编辑

$Checkbox&$i并不能表示前面创建的控件ID变量,要现实循环处理控件ID的变量,可以用数组的变量来定义控件ID。
修改如下:
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Dim $Checkbox[9]
$Form1 = GUICreate("全选\反选", 261, 251, 340, 162)
$Checkbox[0] = GUICtrlCreateCheckbox("1", 50, 50, 25, 17)
$Checkbox[1] = GUICtrlCreateCheckbox("2", 120, 50, 25, 17)
$Checkbox[2] = GUICtrlCreateCheckbox("3", 190, 50, 25, 17)
$Checkbox[3] = GUICtrlCreateCheckbox("4", 50, 100, 25, 17)
$Checkbox[4] = GUICtrlCreateCheckbox("5", 120, 100, 25, 17)
$Checkbox[5] = GUICtrlCreateCheckbox("6", 190, 100, 25, 17)
$Checkbox[6] = GUICtrlCreateCheckbox("7", 50, 150, 25, 17)
$Checkbox[7] = GUICtrlCreateCheckbox("8", 120, 150, 25, 17)
$Checkbox[8] = GUICtrlCreateCheckbox("9", 190, 150, 25, 17)
$Group1 = GUICtrlCreateGroup("10", 24, 24, 209, 169)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button = GUICtrlCreateButton("全选", 90, 210, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
Dim $Checkbox,$B=True
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button
                 If $B=True Then
                         For $i=0 To 8
                         GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
                            GUICtrlSetData($Button,'反选')
                            Next
                          $B=False
               Else
                        For $i=0 To 8
                        If GUICtrlRead($Checkbox[$i])=1 then
                   GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED )
                         Elseif GUICtrlRead($Checkbox[$i])=4 then
                   GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
                   Endif
                           Next
                           $B=True
                           GUICtrlSetData($Button,'全选')
                           Endif
        EndSwitch
WEnd
 楼主| 发表于 2009-7-23 10:15:57 | 显示全部楼层
那这个 For $i=3 To 11  是什么意思。
看了半天没看懂
发表于 2009-7-23 10:18:22 | 显示全部楼层
不理解其中的奥妙~
发表于 2009-7-23 11:18:06 | 显示全部楼层
GUICtrlCreate*创建的控件ID都是从3开始累加的,$checkbox & $i 这一句咋看之下没明白是什么意思。仔细看看,可以直接用$i代替,或者用Eval("Checkbox" & $i),这种情况下,$i的起始量必须要设为1,终止量 ...
pusofalse 发表于 2009-7-22 23:40


有高人已经回答了
 楼主| 发表于 2009-7-23 12:46:07 | 显示全部楼层

看到了 我还以为没人回应了  就开个新贴。
发表于 2009-7-23 13:01:12 | 显示全部楼层
这段代码是我当时提出来的,由顽固不化和lynfr8两位前辈帮助解决的。
你所说的这个问题已经有贴友提过了:http://www.autoitx.com/forum.php ... p;extra=&page=1
而且有贴友给出了解答。
发表于 2009-7-23 13:50:58 | 显示全部楼层
终于明白了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-2 11:36 , Processed in 0.071080 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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