(已解决)如何获取GUICtrlCreateCheckbox复选框选中数量
本帖最后由 minghui 于 2010-8-15 15:44 编辑如何获取GUICtrlCreateCheckbox复选框选中数量,比如有10个GUICtrlCreateCheckbox复选框,我随便勾选了几个,要如何获取它的勾选数量呢! GUICreate("Form1", 600, 450)
$Checkbox1 = GUICtrlCreateCheckbox("复选框 - 1", 40, 30, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("复选框 - 2", 160, 30, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox("复选框 - 3", 280, 30, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("复选框 - 4", 400, 30, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("复选框 - 5", 40, 80, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox("复选框 - 6", 160, 80, 97, 17)
$Checkbox7 = GUICtrlCreateCheckbox("复选框 - 7", 280, 80, 97, 17)
$Checkbox8 = GUICtrlCreateCheckbox("复选框 - 8", 400, 80, 97, 17)
$Checkbox9 = GUICtrlCreateCheckbox("复选框 - 9", 40, 130, 97, 17)
$Checkbox10 = GUICtrlCreateCheckbox("复选框 - 10", 160, 130, 97, 17)
$Checkbox11 = GUICtrlCreateCheckbox("复选框 - 11", 280, 130, 97, 17)
$Checkbox12 = GUICtrlCreateCheckbox("复选框 - 12", 400, 130, 97, 17)
$b = GUICtrlCreateButton('检测数量', 130, 200, 150, 25)
GUISetState()
$sl = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Checkbox1 To $Checkbox12
If GUICtrlRead($nMsg) = 1 Then $sl += 1
If GUICtrlRead($nMsg) = 4 Then $sl -= 1
Case $b
MsgBox(0, 0, $sl)
EndSwitch
WEnd For ...
If GUICtrlRead($ID) = 1 Then 已选中
next 本帖最后由 水木子 于 2010-8-15 15:05 编辑
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
GUICreate("Form1", 600, 450)
$Checkbox1 = GUICtrlCreateCheckbox("复选框 - 1", 40, 30, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("复选框 - 2", 160, 30, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox("复选框 - 3", 280, 30, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("复选框 - 4", 400, 30, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("复选框 - 5", 40, 80, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox("复选框 - 6", 160, 80, 97, 17)
$Checkbox7 = GUICtrlCreateCheckbox("复选框 - 7", 280, 80, 97, 17)
$Checkbox8 = GUICtrlCreateCheckbox("复选框 - 8", 400, 80, 97, 17)
$Checkbox9 = GUICtrlCreateCheckbox("复选框 - 9", 40, 130, 97, 17)
$Checkbox10 = GUICtrlCreateCheckbox("复选框 - 10", 160, 130, 97, 17)
$Checkbox11 = GUICtrlCreateCheckbox("复选框 - 11", 280, 130, 97, 17)
$Checkbox12 = GUICtrlCreateCheckbox("复选框 - 12", 400, 130, 97, 17)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $Checkbox1 To $Checkbox12
$nText = ''
For $i = $Checkbox1 To $Checkbox12
If BitAND(GUICtrlRead($i), $GUI_CHECKED) Then $nText &= '复选框 - ' & $i - 2 & ' 被勾选' & @CRLF
Next
MsgBox(0, '被选项目', $nText)
EndSwitch
WEnd 谢谢! 楼上两位前辈, 我的最终目的是点出确认按钮的时候,就输出勾选了几个. 比如勾选了一个就返回1 , 两个就返回2 勾选N个就返回N这样 谢谢afan版主,我怎么就没想到+1呢! 继续努力学习 回复 5# afan
Case $Checkbox1 To $Checkbox12
这句太精彩了,又学到一招。多谢 又学到了!! 感谢,感谢,努力学习中,非常感谢 本帖最后由 dnvplj 于 2015-4-6 16:36 编辑
回复 5# afan
请教afan版主,如何让选中的数量在“$Label1 = GUICtrlCreateLabel("Label1", 48, 64, 36, 17)”上显示,而不是在MsgBox上显,并同时显被选中的名称,如“复选框 ”(您现在的列子),多谢了。 回复 10# dnvplj GUICreate("Form1", 600, 450)
$Checkbox1 = GUICtrlCreateCheckbox("复选框 - 1", 40, 30, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("复选框 - 2", 160, 30, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox("复选框 - 3", 280, 30, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("复选框 - 4", 400, 30, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("复选框 - 5", 40, 80, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox("复选框 - 6", 160, 80, 97, 17)
$Checkbox7 = GUICtrlCreateCheckbox("复选框 - 7", 280, 80, 97, 17)
$Checkbox8 = GUICtrlCreateCheckbox("复选框 - 8", 400, 80, 97, 17)
$Checkbox9 = GUICtrlCreateCheckbox("复选框 - 9", 40, 130, 97, 17)
$Checkbox10 = GUICtrlCreateCheckbox("复选框 - 10", 160, 130, 97, 17)
$Checkbox11 = GUICtrlCreateCheckbox("复选框 - 11", 280, 130, 97, 17)
$Checkbox12 = GUICtrlCreateCheckbox("复选框 - 12", 400, 130, 97, 17)
$Label1 = GUICtrlCreateLabel('勾选信息', 40, 200, 150, 200)
GUICtrlSetColor(-1, 0x111188)
GUISetState()
Local $sl = 0, $Names = ''
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Checkbox1 To $Checkbox12
If GUICtrlRead($nMsg) = 1 Then
$sl += 1
$Names &= GUICtrlRead($nMsg, 1) & @LF
Else
$sl -= 1
$Names = StringReplace($Names, GUICtrlRead($nMsg, 1) & @LF, '')
EndIf
GUICtrlSetData($Label1, '已勾选 ' & $sl & ' 个:' & @LF & $Names)
EndSwitch
WEnd 回复 11# afan
您好afan版主,因我的水平有限,我认为这样提问就能解决问题,可是,在使用上出现了问题。我想达到的效果是下图中所示,给您添麻烦了。
学习了。。。。。。。
页:
[1]