动态生成的按钮,如何判断哪个被点击?(已解决)
本帖最后由 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
本帖最后由 yamakawa 于 2017-9-2 17:33 编辑
改了下,理论上可以通用
#include <GUIConstantsEx.au3>
Example()
Func Example()
; Create a GUI with various controls.
Local $button, $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] = $temp
$button[$i] = GUICtrlRead($temp)
$i += 1
ReDim $button[$i + 1]
EndSwitch
For $ii = 0 To UBound($button) - 1
If $button[$ii] = $nmsg Then MsgBox(0, "", $button[$ii])
Next
EndIf
WEnd
; Delete the previous GUI and all controls.
GUIDelete($hGUI)
EndFunc ;==>Example
回复 2# yamakawa
非常感谢!!!
页:
[1]