找回密码
 加入
搜索
查看: 1428|回复: 2

[GUI管理] 动态生成的按钮,如何判断哪个被点击?(已解决)

[复制链接]
发表于 2017-9-1 16:09:43 | 显示全部楼层 |阅读模式
本帖最后由 sellkingfly 于 2017-9-2 19:21 编辑

麻烦大家帮忙看下:

每点击一次生成按钮生成一个新按钮。
然后如何判断生成的哪个按钮被点击了。

下边???中间的语句怎么改才能实现呢?



多谢多谢!
#include <GUIConstantsEx.au3>

Example()

Func Example()
        ; Create a GUI with various controls.
        Local $hGUI = GUICreate("Example")
        Local $idOK = GUICtrlCreateButton("create button", 310, 370, 85, 25)

        ; Display the GUI.
        GUISetState(@SW_SHOW, $hGUI)

        ; Loop until the user exits.
        Global $i = 1
        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                        Case $idOK
                                Assign('bb', 'b' & $i, 2)
                                Assign(Eval('bb'), GUICtrlCreateButton("button " & $i, 20, $i * 30, 80, 30))
                                $i = $i + 1
                EndSwitch
                
;?????????????????????????????????????????????????????????????
                                For $j = 1 To 100
                                        Assign('cc','b' & $j, 2)
                                        Switch GUIGetMsg
                                                
                                                Case Eval('cc')
                                                        MsgBox(0, '', 'you clicked button: ' & $j)
                                        EndSwitch
                                Next
;?????????????????????????????????????????????????????????????                                
                
        WEnd

        ; Delete the previous GUI and all controls.
        GUIDelete($hGUI)
EndFunc   ;==>Example
发表于 2017-9-1 18:24:43 | 显示全部楼层
本帖最后由 yamakawa 于 2017-9-2 17:33 编辑

改了下,理论上可以通用
#include <GUIConstantsEx.au3>

Example()

Func Example()
        ; Create a GUI with various controls.
        Local $button[1][2], $i = 0, $temp
        Local $hGUI = GUICreate("Example")
        Local $idOK = GUICtrlCreateButton("create button", 310, 370, 85, 25)

        ; Display the GUI.
        GUISetState(@SW_SHOW, $hGUI)

        ; Loop until the user exits.
        While 1
                $nmsg = GUIGetMsg()
                If $nmsg Then
                        Switch $nmsg
                                Case $GUI_EVENT_CLOSE
                                        ExitLoop
                                Case $idOK
                                        $temp = GUICtrlCreateButton("button " & $i + 1, 20, $i * 30, 80, 30)
                                        $button[$i][0] = $temp
                                        $button[$i][1] = GUICtrlRead($temp)
                                        $i += 1
                                        ReDim $button[$i + 1][2]
                        EndSwitch
                        For $ii = 0 To UBound($button) - 1
                                If $button[$ii][0] = $nmsg Then MsgBox(0, "", $button[$ii][1])
                        Next
                EndIf
        WEnd

        ; Delete the previous GUI and all controls.
        GUIDelete($hGUI)
EndFunc   ;==>Example
 楼主| 发表于 2017-9-2 19:20:09 | 显示全部楼层
回复 2# yamakawa

非常感谢!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-3-28 15:55 , Processed in 0.074393 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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