菜鸟求教Tab中的全选
本帖最后由 duyan 于 2011-4-21 22:07 编辑#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Tab中的全选示例", 339, 254, 193, 125)
GUISetIcon("E:\ICON\843.ico", -1)
$tab = GUICtrlCreateTab(10, 10, 319, 200)
$tab0 = GUICtrlCreateTabItem("注册")
GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
$Checkbox1 = GUICtrlCreateCheckbox("注册1", 32, 34, 73, 17)
$Checkbox2 = GUICtrlCreateCheckbox("注册2", 32, 74, 73, 17)
$Checkbox3 = GUICtrlCreateCheckbox("注册3", 32, 114, 73, 17)
$Checkbox4 = GUICtrlCreateCheckbox("注册4", 32, 154, 73, 17)
$tab1 = GUICtrlCreateTabItem("测试")
$Checkbox5 = GUICtrlCreateCheckbox("测试5", 32, 34, 73, 17)
$Checkbox6 = GUICtrlCreateCheckbox("测试6", 32, 74, 73, 17)
$Checkbox7 = GUICtrlCreateCheckbox("测试7", 32, 114, 73, 17)
$Checkbox8 = GUICtrlCreateCheckbox("测试8", 32, 154, 73, 17)
$tab2 = GUICtrlCreateTabItem("学习")
$Checkbox9 = GUICtrlCreateCheckbox("学习9", 32, 34, 73, 17)
$Checkbox10 = GUICtrlCreateCheckbox("学习10", 32, 74, 73, 17)
$Checkbox11 = GUICtrlCreateCheckbox("学习11", 32, 114, 73, 17)
$Checkbox12 = GUICtrlCreateCheckbox("学习12", 32, 154, 73, 17)
GUICtrlCreateTabItem("") ; end tabitem definition
$Button1 = GUICtrlCreateButton("全选", 16, 220, 97, 25, 0)
$Button2 = GUICtrlCreateButton("全不选", 126, 220, 97, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
For $i=1 to 12
$T="Checkbox"&$i
GUICtrlSetState(Eval($T),$GUI_CHECKED)
Next
Case $Button2
For $i=1 to 12
$T="Checkbox"&$i
GUICtrlSetState(Eval($T),$GUI_UNCHECKED)
Next
EndSwitch
WEnd
这是论坛中的一个全选的例子,我稍作修改把12个Checkbox放到了3个Tab页中,我想知道的是如何才能做到分别全选,即点击不同的Tab页,则全选Tab页中包含的4个Checkbox,而不是全选12个Checkbox。For $i=1 to 4 可实现第一个Tab页的全选。后2个应如何实现呢?谢谢!
为什么别人的源码是彩色的,而我的是bw的 本帖最后由 netegg 于 2011-4-21 22:31 编辑
创建的时候就自己定好,比如1to10是第一个分页,11to20是第二个分页,等等,然后在点击中把条件改下,确定当前显示的是哪个分页 #include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("guioneventmode",1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Tab中的全选示例", 339, 254, 193, 125)
GUISetIcon("E:\ICON\843.ico", -1)
$tab = GUICtrlCreateTab(10, 10, 319, 200)
$tab0 = GUICtrlCreateTabItem("注册")
GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
$Checkbox1 = GUICtrlCreateCheckbox("注册1", 32, 34, 73, 17)
$Checkbox2 = GUICtrlCreateCheckbox("注册2", 32, 74, 73, 17)
$Checkbox3 = GUICtrlCreateCheckbox("注册3", 32, 114, 73, 17)
$Checkbox4 = GUICtrlCreateCheckbox("注册4", 32, 154, 73, 17)
$tab1 = GUICtrlCreateTabItem("测试")
$Checkbox5 = GUICtrlCreateCheckbox("测试5", 32, 34, 73, 17)
$Checkbox6 = GUICtrlCreateCheckbox("测试6", 32, 74, 73, 17)
$Checkbox7 = GUICtrlCreateCheckbox("测试7", 32, 114, 73, 17)
$Checkbox8 = GUICtrlCreateCheckbox("测试8", 32, 154, 73, 17)
$tab2 = GUICtrlCreateTabItem("学习")
$Checkbox9 = GUICtrlCreateCheckbox("学习9", 32, 34, 73, 17)
$Checkbox10 = GUICtrlCreateCheckbox("学习10", 32, 74, 73, 17)
$Checkbox11 = GUICtrlCreateCheckbox("学习11", 32, 114, 73, 17)
$Checkbox12 = GUICtrlCreateCheckbox("学习12", 32, 154, 73, 17)
GUICtrlCreateTabItem("") ; end tabitem definition
$Button1 = GUICtrlCreateButton("全选", 16, 220, 97, 25, 0)
$Button2 = GUICtrlCreateButton("全不选", 126, 220, 97, 25, 0)
GUICtrlSetOnEvent($tab,"tab")
GUICtrlSetOnEvent($Button1,"BUTTON")
GUICtrlSetOnEvent($Button2,"BUTTON")
GUISetOnEvent($GUI_EVENT_CLOSE,"CLOSE")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
Sleep(1000)
WEnd
Func CLOSE()
Exit
EndFunc
Func BUTTON()
Switch @GUI_CtrlId
Case $Button1
For $i=1 to 12
$T="Checkbox"&$i
GUICtrlSetState(Eval($T),$GUI_CHECKED)
Next
Case $Button2
For $i=1 to 12
$T="Checkbox"&$i
GUICtrlSetState(Eval($T),$GUI_UNCHECKED)
Next
EndSwitch
EndFunc
Func tab()
$tab = GUICtrlRead(@GUI_CtrlId)
Switch $tab
Case 0
For $i=1 to 4
$T="Checkbox"&$i
GUICtrlSetState(Eval($T),$GUI_CHECKED)
Next
Case 1
For $i=5 to 8
$T="Checkbox"&$i
GUICtrlSetState(Eval($T),$GUI_CHECKED)
Next
Case 2
For $i=9 to 12
$T="Checkbox"&$i
GUICtrlSetState(Eval($T),$GUI_CHECKED)
Next
EndSwitch
EndFunc
for循环就可以了!正如楼上的一样!
页:
[1]