#Region options, includes
Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
#include <GUIConstantsEx.au3>
#EndRegion options, includes
Global Const $nCols = 2, $nRows = 6, $nSpacer = 10, $nBtnWidth = 150, $nBtnHeight = 30
Global $xName = 0;, $xID = 0
Global $nGUIWidth = ($nCols * $nBtnWidth) + (($nCols + 1) * $nSpacer)
Global $nGUIHeight = ($nRows * $nBtnHeight) + (($nRows + 1) * $nSpacer)
Global $hMainGUI = GUICreate("Calculated GUI", $nGUIWidth, $nGUIHeight, -1, -1)
For $xRows = 1 to $nRows ;in this arrangement, tabbing is left to right, then next row
For $xCols = 1 to $nCols ;reverse the order of this line with the prior line for top to bottom tabbing, then next col
$xName += 1
;~ $xID += 1 ; not used anymore
Global $Dummy = GUICtrlCreateButton("Button" & $xName, _
($nBtnWidth * ($xCols - 1)) + (($xCols - 1) * $nSpacer) + $nSpacer, _
($nBtnHeight* ($xRows - 1)) + (($xRows - 1) * $nSpacer) + $nSpacer, _
$nBtnWidth, _
$nBtnHeight)
GUICtrlSetOnEvent(-1, "Handler")
Assign('BttnIndex' & $Dummy, $Dummy, 2) ; better idea ?
Assign('BttnName' & $Dummy, $xName, 2)
Assign('BttnIndexFromName' & $xName, $Dummy, 2) ; and you can do this too =)
Next
Next
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseApp")
GUISetState(@SW_SHOW)
While 1
Sleep(10)
WEnd
Func CloseApp()
Exit
EndFunc
Func Handler()
MsgBox(0,0,"Button " & Eval('BttnName' & @GUI_CtrlId) & ' is controlID ' & Eval('BttnIndex' & @GUI_CtrlId) )
EndFunc
this approach may end up having a more practical use