piaoa_998 发表于 2010-7-27 16:56:10

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

有多个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

piaoa_998 发表于 2010-7-27 16:56:49

坐等回复,拜托了

Ziya 发表于 2010-7-27 16:57:41

为啥会需要点击那么多按钮?
能否具体描述一下你的思路,看看有没有其他解决办法.?

piaoa_998 发表于 2010-7-27 17:01:21

就是希望用button实现类似checkbox的功能,因为button在属性里面可以设置用图片代替,我是希望用图片代替我要做的选项,而checkbox貌似不可以用图片代替

afan 发表于 2010-7-27 17:01:25

这种搞法还真没见过,有必要这样组合吗

piaoa_998 发表于 2010-7-27 17:06:12

呵呵,因为产生了这样的想法,不确定有没有可行性,还请高手们指教

Ziya 发表于 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
这样貌似可以

piaoa_998 发表于 2010-7-27 17:22:33

感谢楼上的高手,确实可以实现


还有个问题:如果需要实现的是多个button,并且允许多个button相加可以实现一种功能,每个button单独点击的时候又可以实现单独的功能,有什么好方法吗

piaoa_998 发表于 2010-7-27 17:24:14

因为涉及的button比较多,如果用if判断,语句很复杂,不知道能有什么好方法吗?

Ziya 发表于 2010-7-27 17:26:04

别的暂时就没想到了- -

piaoa_998 发表于 2010-7-27 17:26:05

或者用数组的话要怎么实现呢?

afan 发表于 2010-7-27 17:40:32

LZ是想做游戏?

pusofalse 发表于 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)

zcx880517 发表于 2010-7-27 21:44:16

学习了。。真不错

0633zhou 发表于 2010-7-29 23:00:56

学习了。。真不错
页: [1]
查看完整版本: 如何用button实现类似checkbox的记忆住是否被点击的操作