For $i=3 To 11
本帖最后由 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吗? 这个我也不是很清楚,留名等高手解惑 本帖最后由 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
$Form1 = GUICreate("全选\反选", 261, 251, 340, 162)
$Checkbox = GUICtrlCreateCheckbox("1", 50, 50, 25, 17)
$Checkbox = GUICtrlCreateCheckbox("2", 120, 50, 25, 17)
$Checkbox = GUICtrlCreateCheckbox("3", 190, 50, 25, 17)
$Checkbox = GUICtrlCreateCheckbox("4", 50, 100, 25, 17)
$Checkbox = GUICtrlCreateCheckbox("5", 120, 100, 25, 17)
$Checkbox = GUICtrlCreateCheckbox("6", 190, 100, 25, 17)
$Checkbox = GUICtrlCreateCheckbox("7", 50, 150, 25, 17)
$Checkbox = GUICtrlCreateCheckbox("8", 120, 150, 25, 17)
$Checkbox = 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 那这个 For $i=3 To 11是什么意思。
看了半天没看懂 不理解其中的奥妙~ GUICtrlCreate*创建的控件ID都是从3开始累加的,$checkbox & $i 这一句咋看之下没明白是什么意思。仔细看看,可以直接用$i代替,或者用Eval("Checkbox" & $i),这种情况下,$i的起始量必须要设为1,终止量 ...
pusofalse 发表于 2009-7-22 23:40 http://www.autoitx.com/images/common/back.gif
有高人已经回答了 哦
看到了 我还以为没人回应了就开个新贴。 这段代码是我当时提出来的,由顽固不化和lynfr8两位前辈帮助解决的。
你所说的这个问题已经有贴友提过了:http://www.autoitx.com/forum.php?mod=viewthread&tid=8372&extra=&page=1
而且有贴友给出了解答。 终于明白了
页:
[1]