Global $aButNum[25] ;按钮总数
Global $iNumber = 5 ;每行按钮数量
Global $iSpacingX = 50, $iSpacingY = 50 ;垂直、水平,间距
Opt('GUIOnEventMode', 1)
GUICreate('循环创建按钮', 300, 300)
GUISetOnEvent(-3, '_ButtonEvents')
For $i = 0 To UBound($aButNum) - 1
$aButNum[$i] = GUICtrlCreateButton($i + 1, $iSpacingX * Mod($i, $iNumber) + 25, $iSpacingY * Floor($i / $iNumber) + 25, 50, 50)
GUICtrlSetOnEvent(-1, '_ButtonEvents')
Next
GUISetState()
While 1
Sleep(250)
WEnd
Func _ButtonEvents()
Switch @GUI_CtrlId
Case -3
Exit
Case $aButNum[0] To $aButNum[UBound($aButNum) - 1]
MsgBox(0, '', '按钮 - ' & @GUI_CtrlId - 2)
EndSwitch
EndFunc ;==>_ButtonEvents
|