找回密码
 加入
搜索
查看: 3926|回复: 14

[GUI管理] 如何用button实现类似checkbox的记忆住是否被点击的操作

  [复制链接]
发表于 2010-7-27 16:56:10 | 显示全部楼层 |阅读模式
有多个button,点任意的button实现不同的操作,期望实现的功能:点击多个button后能组合执行对于button的函数,目前遇到的困难是,无法判断哪些button被点击了,代码如下:

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 380, 514, 250, 130)
$Button1 = GUICtrlCreateButton("Button1 ", 48, 64, 97, 49, 0)
$Button2 = GUICtrlCreateButton("Button2 ", 48, 152, 97, 49, 0)
GUISetState()
#EndRegion ### END Koda GUI section ###

While 1
        Switch GUIGetMsg()
        Case $Button1 and $Button2
                Start1()
                                 Start2()               
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd


Func Start1()
        msgbox(1,"","1111111")
EndFunc


Func Start2()
        msgbox(1,"","22222")
EndFunc
 楼主| 发表于 2010-7-27 16:56:49 | 显示全部楼层
坐等回复,拜托了
发表于 2010-7-27 16:57:41 | 显示全部楼层
为啥会需要点击那么多按钮?
能否具体描述一下你的思路,看看有没有其他解决办法.?
 楼主| 发表于 2010-7-27 17:01:21 | 显示全部楼层
就是希望用button实现类似checkbox的功能,因为button在属性里面可以设置用图片代替,我是希望用图片代替我要做的选项,而checkbox貌似不可以用图片代替
发表于 2010-7-27 17:01:25 | 显示全部楼层
这种搞法还真没见过,有必要这样组合吗
 楼主| 发表于 2010-7-27 17:06:12 | 显示全部楼层
呵呵,因为产生了这样的想法,不确定有没有可行性,还请高手们指教
发表于 2010-7-27 17:13:21 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 321, 94, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 24, 8, 81, 33)
$Button2 = GUICtrlCreateButton("Button2", 152, 8, 81, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$a = 0
$b = 0

While 1
        If $a + $b = 2         Then 
        MsgBox(0,"","Done")
        $a = 0
        $b = 0
        EndIf
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $a = 1
                Case $Button2
                        $b = 1
        EndSwitch
WEnd
这样貌似可以

评分

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

查看全部评分

 楼主| 发表于 2010-7-27 17:22:33 | 显示全部楼层
感谢楼上的高手,确实可以实现


还有个问题:如果需要实现的是多个button,并且允许多个button相加可以实现一种功能,每个button单独点击的时候又可以实现单独的功能,有什么好方法吗
 楼主| 发表于 2010-7-27 17:24:14 | 显示全部楼层
因为涉及的button比较多,如果用if判断,语句很复杂,不知道能有什么好方法吗?
发表于 2010-7-27 17:26:04 | 显示全部楼层
别的暂时就没想到了- -
 楼主| 发表于 2010-7-27 17:26:05 | 显示全部楼层
或者用数组的话要怎么实现呢?
发表于 2010-7-27 17:40:32 | 显示全部楼层
LZ是想做游戏?
发表于 2010-7-27 17:56:41 | 显示全部楼层
本帖最后由 pusofalse 于 2010-7-27 18:15 编辑

为每一个按钮赋一个比特值,第一个按钮赋为1、第二个赋为2、第三个4、第四个8,依此。
每截取到一次点击操作,用BitXOR异一下,如果相异的结果等于3,说明已经点击了第1、2个按钮,如果等于14,说明点击了第2、3、4个按钮。但这样做会没法判断点击的顺序。
Global $iBitFlags
Const $iButtonMin = 3
Const $iButtonMax = $iButtonMin + 4 - 1

$hGUI = GUICreate("Test", 400, 300)
For $i = 1 To 4
        GUICtrlCreateButton("Button " & $i, 20, $i * 30, 90, 20)
Next

GUISetState()
While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
        Case $iButtonMin To $iButtonMax
                $iBitFlags = BitXOR($iBitFlags, BitShift(1, 0 - $iMsg + $iButtonMin))
                Switch $iBitFlags
                Case 7
                        MsgBox(0, "OK", "What do you wanna do?")
                        $iBitFlags = 0
                Case 14
                        ;;;;;
                EndSwitch

        Case -3
                ExitLoop
        EndSwitch
WEnd
GUIDelete($hGUI)

评分

参与人数 1贡献 +5 收起 理由
afan + 5

查看全部评分

发表于 2010-7-27 21:44:16 | 显示全部楼层
学习了。。真不错
发表于 2010-7-29 23:00:56 | 显示全部楼层
学习了。。真不错
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-7 23:49 , Processed in 0.101120 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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