(已解决)这个应该怎么改?Guictrlread的问题还是哪里的问题?
本帖最后由 yarsye 于 2010-7-26 16:14 编辑我想实现的是 建立3个checkbox 让用户选 然后 判断用户选了哪几个
例如 选择1,3checkbox 然后点ok ,1,3下面的函数应该执行
想法有 但是不知道怎么实现
有太多东西部会 让人着实着急了一把
感谢你的阅读 盼望高手解答#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)
Global $box1, $msg ,$ok,$button1,$box2,$checked,$i,$box3,$ch,$chked
$ch= 0
GUICreate("My GUI Checkbox")
$box1 = GUICtrlCreateCheckbox("box1", 10, 10, 120, 20)
$box2 = GUICtrlCreateCheckbox("box2",10,30,120,20)
$box3 = GUICtrlCreateCheckbox("box3", 10, 50, 120 ,20)
$button1=GUICtrlCreateButton("button1",120,120,120,20)
GUISetState()
GUICtrlSetOnEvent($button1,"ok")
;GUICtrlSetOnEvent($box1,"func1")
For $i = 1 To 2
If GUICtrlRead (Eval("$chkbox"&$i)) = $GUI_CHECKED Then
$ch = $ch + BitShift (1,1-$i )
EndIf
Next
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Func ok()
For $i = 1 To 2
Execute ("func"&$i&"("&$ch&")")
Next
EndFunc
Func func1($ch)
If BitAND($ch,1) = 0 Then
MsgBox(0,$ch,"2")
Return
EndIf
EndFunc
Func func2($ch)
If BitAND($ch,2) = 0 Then
MsgBox(0,$ch,"3")
Return
EndIf
EndFunc
Func func3($ch)
If BitAND($ch,5) = 0 Then
MsgBox(0,$ch,"4")
Return
EndIf
EndFunc
楼主是这个意思吗?#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Local $Form, $box1, $msg, $button1, $box2, $box3, $ch
$ch = 0
$Form = GUICreate("My GUI Checkbox")
$box1 = GUICtrlCreateCheckbox("box1", 10, 10, 120, 20)
$box2 = GUICtrlCreateCheckbox("box2", 10, 30, 120, 20)
$box3 = GUICtrlCreateCheckbox("box3", 10, 50, 120, 20)
$button1 = GUICtrlCreateButton("button1", 120, 120, 120, 20)
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $button1
readcheck()
EndSelect
WEnd
Func readcheck()
For $i = 1 To 3
$ch = "box" & $i
If GUICtrlRead(Eval($ch)) = $GUI_UNCHECKED Then MsgBox(0, 0, $ch & '没选择')
If GUICtrlRead(Eval($ch)) = $GUI_CHECKED Then MsgBox(0, 0, $ch & '已选择')
Next
EndFunc ;==>readcheck Opt('GUIOnEventMode', 1)
GUICreate('My GUI Checkbox')
GUISetOnEvent(-3, '_exit')
Local $box
$box = GUICtrlCreateCheckbox('box1', 10, 10, 120, 20)
$box = GUICtrlCreateCheckbox('box2', 10, 30, 120, 20)
$box = GUICtrlCreateCheckbox('box3', 10, 50, 120, 20)
$button1 = GUICtrlCreateButton('执行勾选项', 120, 120, 120, 20)
GUICtrlSetOnEvent(-1, 'ok')
GUISetState()
While 1
Sleep(10)
WEnd
Func _exit()
Exit
EndFunc ;==>_exit
Func ok()
For $i = 0 To 2
If GUICtrlRead($box[$i]) = 1 Then Call('func' & $i)
Next
EndFunc ;==>ok
Func func0()
MsgBox(0, '执行', 'box1 已勾选')
EndFunc ;==>func0
Func func1()
MsgBox(0, '执行', 'box2 已勾选')
EndFunc ;==>func1
Func func2()
MsgBox(0, '执行', 'box3 已勾选')
EndFunc ;==>func2 回复 2# 3mile
你改的太漂亮了 正是我想要的情况 谢谢
简单明了 一看就懂(但是我没写出来)
效率高 回复 3# afan
老大 你太专业了 谢谢 我也有这个问题,学习了
页:
[1]