找回密码
 加入
搜索
查看: 2569|回复: 5

[AU3基础] (已解决)这个应该怎么改?Guictrlread的问题还是哪里的问题?

[复制链接]
发表于 2010-7-26 12:26:29 | 显示全部楼层 |阅读模式
本帖最后由 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

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-7-26 14:04:17 | 显示全部楼层
楼主是这个意思吗?
#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

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-7-26 14:29:08 | 显示全部楼层
Opt('GUIOnEventMode', 1)

GUICreate('My GUI Checkbox')
GUISetOnEvent(-3, '_exit')
Local $box[3]
$box[0] = GUICtrlCreateCheckbox('box1', 10, 10, 120, 20)
$box[1] = GUICtrlCreateCheckbox('box2', 10, 30, 120, 20)
$box[2] = 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
 楼主| 发表于 2010-7-26 16:13:03 | 显示全部楼层
回复 2# 3mile


    你改的太漂亮了 正是我想要的情况 谢谢
简单明了 一看就懂  (但是我没写出来)
效率高
 楼主| 发表于 2010-7-26 16:13:26 | 显示全部楼层
回复 3# afan


    老大 你太专业了 谢谢
发表于 2011-10-24 00:44:43 | 显示全部楼层
我也有这个问题,学习了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-1 12:22 , Processed in 0.076218 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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