Jump to content

GUIcreatbutton with for loop.


nlta1992
 Share

Recommended Posts

  • Moderators

nlta1992,

Something like this perhaps?

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

; Array to hold button ControlIDs
Global $aButton[11]

$hGUI = GUICreate("Test", 500, 500)

; A double loop to space out the buttons - but you could very easily have a single one instead
For $i = 0 To 1
    For $j = 1 To 5
        $iIndex = ($i * 5) + $j
        ; Create button using a suitable algorithm to locate it
        $aButton[$iIndex] = GUICtrlCreateButton("Button " & $iIndex, 10 + (250 * $i), ($j * 50) - 30, 80, 30)
    Next
Next

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            ; See if a button was pressed
            For $i = 1 To 10
                If $iMsg = $aButton[$i] Then
                    ; Do what is necessary
                    MsgBox($MB_SYSTEMMODAL, "Pressed", "Button " & $i)
                    ; No point in looking further
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

antonioj84,

Simply replace GUICtrlCreateButton with GUICtrlCreateRadio.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

adding unique name radio button

; Array to hold button ControlIDs
;Global $aButton[11]    ; 4x 5 = 21
Global $aButton[11]
Global $aName[11]=["0","Ajohn","Bjohn","Cjohn","Djohn","Ejohn","Fjohn","Jjohn","Hjohn","Ijohn","Jjohn"]
$hGUI = GUICreate("Test", 500, 500)

; A double loop to space out the buttons - but you could very easily have a single one instead
For $i = 0 To 1        ; 0 to 3  x4
    For $j = 1 To 5
        $iIndex = ($i * 5) + $j
        ; Create button using a suitable algorithm to locate it
        $aButton[$iIndex] = GUICtrlCreateRadio($aName[$iIndex] &$iIndex, 10 + (150 * $i), ($j * 50) - 30, 80, 30) ; $index,20
    Next
Next

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            ; See if a button was pressed
            For $i = 1 To 10             ;20
                If $iMsg = $aButton[$i] Then
                    ; Do what is necessary
                    MsgBox($MB_SYSTEMMODAL, "Pressed", "Button " & $i)
                    ; No point in looking further
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...