Jump to content
nlta1992

GUIcreatbutton with for loop.

Recommended Posts

nlta1992

I want creat GUI, have button 1 to 10, but only use loop for ... to ... step ... next.

Thanks.

Share this post


Link to post
Share on other sites
LeCarre

Could you be more clear on what you need?

Share this post


Link to post
Share on other sites
Melba23

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

  • Like 2

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
nlta1992

Ok thanks Melba23 :D

Share this post


Link to post
Share on other sites
antonioj84

Hey Melba,

Can you show a quick example how would you do that with a check radio button, starting state will be uncheck.

 

Thanks

Share this post


Link to post
Share on other sites
Melba23

antonioj84,

Simply replace GUICtrlCreateButton with GUICtrlCreateRadio.

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
antonioj84

Melba,  your coding style is awesome . 

Share this post


Link to post
Share on other sites
antonioj84

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

 

Share this post


Link to post
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

  • Similar Content

    • faustf
      By faustf
      i guys , like title anyone  have idea if is possible , and if yes if  have example to post ?  i find in forum and in google but  i dont know   how can start  to create  button with icon over toolbar near  clock or is  goog before language layout .
      sorry i not post any script but i dont know  where to start
      thankz
      at  all
    • caramen
      By caramen
      Hmmm i am sorry  i had simular problem but i cant find back post. 
       
      How to hide a gui button ? 
       
      I Want to dodge the variable non déclaréd when i make button in
      if statment 
       
      thx before 
    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • Blois
      By Blois
      Hi Guis,
       
      I need to create keyboard shortcut to navigate the tabs and activate them, but I could not use the code below:
      #include <TabConstants.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> #include <GUIConstantsEx.au3> HotKeySet("^{TAB}", "_TabRight") HotKeySet("^+{TAB}", "_TabLeft") $gui = GUICreate("test",450, 300) $Tab1 = GUICtrlCreateTab(20, 24, 425, 201) $TabSheet1 = GUICtrlCreateTabItem("Tabsheet 1") $lbContagemGrupos2 = GUICtrlCreateLabel("aaaa", 50, 50) GUICtrlSetColor(-1, 0x0000FF) GUICtrlCreateTabItem("") $TabSheet2 = GUICtrlCreateTabItem(" ") $TabSheet3 = GUICtrlCreateTabItem(" ") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _TabRight() $CurPos = _GUICtrlTab_GetCurSel($Tab1) _GUICtrlTab_SetCurSel($Tab1, $CurPos + 1) $tab = "$TabSheet" & $CurPos GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW) Return EndFunc Func _TabLeft() $CurPos = _GUICtrlTab_GetCurSel($Tab1) _GUICtrlTab_SetCurSel($Tab1, $CurPos - 1) $tab = "$TabSheet" & $CurPos GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW) Return EndFunc Exit  
      can you help me?
    • Pricehacker
      By Pricehacker
      Hello again!
      I have tried searching for quite some time now but couldn´t find a single working way to change the class of your GUI that doesn´t include changing it manually after its compilation.
      First or "AutoIt v3 GUI" is a pretty boring name tbh and i would like to spice it up a bit, also, and more importantly, I would like to identify my windows by something other than its title as it will change depending on some factors and im using two different programs independently as multi threading isn't supported.
      Any help is appreciated! Thank you!
×