Jump to content

Recommended Posts

Posted (edited)

You would think I would know this by now, but you know me, it is like kryptonite to Superman.... :P

Could someone give me an example of a simple GUI that uses a array to specify how many buttons it has? Say for example I want to do a GUI with 10 buttons. All 10 would be in a row, and the same size. I remember somewhere someone posted a example, but I can't find it. Can someone help a fellow out?

(I got my hat in my hand here....)

Edited by vollyman
Posted

Hi,

#include <guiconstants.au3>

Global $Button[11][11]

GUICreate("" )

For $a = 1 to 10
    For $b = 1 to 10
        $Button[$a][$b] = GUICtrlCreateButton( "Button[" & $a & "][" & $b & "]" , $a * 45 , $b * 45 , 30 , 30)
    Next
Next

GUISetState( @SW_SHOW )

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

  • Moderators
Posted

Here is another approach.

#include <GuiConstants.au3>

Dim $aButtons[50], $PADDING = 10, $LEFT = 10

GUICreate("Multiple Buttons")
For $i = 0 To 49
    If Mod($i, 10) = 0 And $i <> 0 Then
        $PADDING = 10
        $LEFT += 60
    EndIf
    $aButtons[$i] = GUICtrlCreateButton("Test", $LEFT, $PADDING, 50, 20)
    $PADDING += 30
Next
GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(50)
WEnd
  • Moderators
Posted

I remember somewhere someone posted a example, but I can't find it.

When you first joined the forum, alot of your posts I would show you how to do your GUI's with Arrays.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

I'm trying to make a example array that will show a row of buttons in a GUI. Yes, I'm still having trouble getting the hang of this.

#include <guiconstants.au3>

GUICreate("")
$var = IniReadSection(@ScriptDir & "birthday.ini", "Brenda")
For $i = 1 to $var[0][0]
        GUICtrlCreateButton([$s][0], 70 , 70 , 70 , 30)
Next

GUISetState( @SW_SHOW )

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
Posted

The example you jsut posted would have no way to determine if the user clicked any of the buttons. By doing something like th.meger and big_daddy have posted, you can easily determine which button the user clicked on by doing something like this:

(jsut adds a little bit to the example posted by th.meger)

#include <guiconstants.au3>

Global $Button[11][11]

GUICreate("" )

For $a = 1 to 10
    For $b = 1 to 10
        $Button[$a][$b] = GUICtrlCreateButton( "Button[" & $a & "][" & $b & "]" , $a * 45 , $b * 45 , 30 , 30)
    Next
Next

GUISetState( @SW_SHOW )

Do
    $msg = GUIGetMsg()

    For $i = 1 to 10
        For $j = 1 To 10
            If $msg = $Button[$i][$j] Then
                MsgBox( 0, "", "Perform some action cuz a button was clicked." )
            EndIf
        Next
    Next
Until $msg = $GUI_EVENT_CLOSE

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

  • Moderators
Posted

Is this like what you are wanting?

#include <GuiConstants.au3>

Dim $aButtons[50], $PADDING = 10, $LEFT = 10

$aInfo = IniReadSection(@ScriptDir & "\birthday.ini", "Brenda")
GUICreate("Multiple Buttons")
For $i = 1 To $aInfo[0][0]
    If Mod($i, 10) = 0 And $i <> 0 Then
        $PADDING = 10
        $LEFT += 60
    EndIf
    $aButtons[$i] = GUICtrlCreateButton($aInfo[$i][0], $LEFT, $PADDING, 50, 20)
    $PADDING += 30
Next
GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(50)
WEnd
  • Moderators
Posted

Unless I missed something this should accomplish what you want.

Adjust $PADDING, $BUTTON_WIDTH, and $BUTTON_HEIGHT to whatever you want.

#include <GuiConstants.au3>

Dim $PADDING = 10, $BUTTON_WIDTH = 50, $BUTTON_HEIGHT = 20

$aInfo = IniReadSection(@ScriptDir & "\birthday.ini", "Brenda")

$GUI = GUICreate("Multiple Buttons", Default, Default, Default, Default, $WS_POPUPWINDOW)

$iButtons = $aInfo[0][0]
Dim $aButtons[$iButtons]
For $i = 1 To $iButtons
    $aButtons[$i - 1] = GUICtrlCreateButton($aInfo[$i][0], $PADDING, _
            ($PADDING * $i) + ($BUTTON_HEIGHT * ($i - 1)), $BUTTON_WIDTH, $BUTTON_HEIGHT)
Next

WinMove($GUI, "", Default, Default, $BUTTON_WIDTH + ($PADDING * 2), _
        ($BUTTON_HEIGHT * $iButtons) + ($PADDING * ($iButtons + 1)))

GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(50)
WEnd
Posted (edited)

Am I explaining this right?

#include <GuiConstants.au3>

Dim $PADDING = 0, $BUTTON_WIDTH = 100, $BUTTON_HEIGHT = 100

$aInfo = IniReadSection(@ScriptDir & "\birthday.ini", "Brenda")

$GUI = GUICreate("Multiple Buttons", Default, Default, Default, Default, $WS_POPUPWINDOW)

$iButtons = $aInfo[0][0]
Dim $aButtons[$iButtons]
For $i = 1 To $iButtons
    $aButtons[$i - 1] = GUICtrlCreateButton($aInfo[$i][1], $PADDING, _
            ($PADDING * $i) + ($BUTTON_HEIGHT * ($i - 1)), _ 
            $BUTTON_WIDTH, $BUTTON_HEIGHT)
Next

WinMove($GUI, "", Default, Default, $BUTTON_WIDTH + ($PADDING * 2), _
        ($BUTTON_HEIGHT * $iButtons) + ($PADDING * ($iButtons + 1)))

GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE   
sleep(100)
WEndoÝ÷ ÛR'u'*'Eën®{ÙØ¦z{"¢v¥jºÚÉ©Ý{aDZí7é¢'~"²Ø^ìÝ7é¢'~b²Ø^½©n{m7èer·µë-á!©Ýج§^¶^}«¥¶È³xb²¯z{azËrêj)º"Ú0"z-Çò+zj/zØb²Ø^âØ[ºÛh­±Ë­¡÷÷)´ß¦ºÛhÍ7ê n¶Ú'°*Þj׬iªëk&îµÚ²}ý·Múhß¡Ú-+!º¸jëh×6For $i = 1 To $iButtons
    $aButtons[$i - 1] = GUICtrlCreateButton($aInfo[$i][1], $PADDING, _
            ($PADDING * $i) + ($BUTTON_HEIGHT * ($i - 1)), _ 
            $BUTTON_WIDTH, $BUTTON_HEIGHT)
Next

This makes the buttons, but I don't understand why it stacks the buttons instead of putting them side by side.

5. The WinMove resizes the GUI to fit the buttons. WHen I commented it out, the buttons still stacked themselfs. :P

Questions:

A - How do I make the buttons side by side?

B - How do I make it so when the button is clicked, something happens?

I tried to put in a case statement, but I don't know how to point to the button I want.

Edited by vollyman
  • Moderators
Posted

Questions:

A - How do I make the buttons side by side?

B - How do I make it so when the button is clicked, something happens?

I tried to put in a case statement, but I don't know how to point to the button I want.

Question A: You just needed to switch the x/y parameters for the buttons, and the width/height for the WinMove.

Question B: The script below has an example of this.

#include <GuiConstants.au3>

HotKeySet("{ESC}", "_Exit")

Opt("GuiOnEventMode", True)

Dim $PADDING = 0, $BUTTON_WIDTH = 100, $BUTTON_HEIGHT = 100

$aInfo = IniReadSection(@ScriptDir & "\birthday.ini", "Brenda")

$GUI = GUICreate("Multiple Buttons", Default, Default, Default, Default, $WS_POPUPWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$iButtons = $aInfo[0][0]
Dim $aButtons[$iButtons]
For $i = 1 To $iButtons
    $aButtons[$i - 1] = GUICtrlCreateButton($aInfo[$i][1], ($PADDING * $i) + _
            ($BUTTON_HEIGHT * ($i - 1)), $PADDING, $BUTTON_WIDTH, $BUTTON_HEIGHT)
    GUICtrlSetOnEvent(-1, "_Buttonclicked")
Next

WinMove($GUI, "", Default, Default, ($BUTTON_HEIGHT * $iButtons) + _
        ($PADDING * ($iButtons + 1)), $BUTTON_WIDTH + ($PADDING * 2))

GUISetState()

While 1
    Sleep(50)
WEnd

Func _Buttonclicked()
    $CTRLID = @GUI_CtrlId
    MsgBox(0, "", "The button you clicked had the text:" & @CRLF & @CRLF & GUICtrlRead($CTRLID))
EndFunc   ;==>_Buttonclicked

Func _Exit()
    Exit
EndFunc   ;==>_Exit

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...