Maffe811 Posted August 4, 2011 Posted August 4, 2011 I made this script as a simple excersize to see if i could make buttons that would change in ammount with the change of a number. And also if i could make the gui change in size acordingly. I might make a v2 with a second GUI where you can change the different values with sliders. Please give any comments you got and if this is helpfull for anyone, please use it! expandcollapse popup;******************************************************************** ;Controlls: ;Button controlls: Global $ButtonHeight = 30 Global $ButtonWidth = 80 ;Left border and spacer controlls: Global $LeftBorder = 10 Global $LeftSpacer = 10 + $ButtonWidth ;Top border and spacer controlls: Global $TopBorder = 10 Global $TopSpacer = 10 + ($ButtonHeight/4) ;Button amount controlls: Global $HorizontalButtonAmount = 4 Global $VerticalButtonAmount = 3 ;******************************************************************** ;Include files: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $HorizontalButtonAmount -= 1;Controll fix ;Gui size: Global $GuiHegiht = ($TopBorder*2)+(($HorizontalButtonAmount*2)*$TopSpacer)+$ButtonHeight Global $GuiWidth = ($LeftSpacer*$VerticalButtonAmount)+$LeftBorder GUICreate("",$GuiWidth,$GuiHegiht) ;Gui create For $x = 0 to $HorizontalButtonAmount*2 step 1*2 ;Creating the buttons horizontally For $i = 0 to $VerticalButtonAmount step 1 ;Creating the buttons vertically GUICtrlCreateButton(($i+1) & " " & ($x/2+1), $LeftBorder+($i*$LeftSpacer),$TopBorder+($x*$TopSpacer),$ButtonWidth,$ButtonHeight) Next Next GUISetState(@SW_SHOW);Show the GUI While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE then exit;If window is closed then exit WEnd [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]
JohnOne Posted August 4, 2011 Posted August 4, 2011 I usually create my guis in a similar fashion when they have a lot of controls the same. If you are looking for a coding exercise, figure out how to make the buttons usable. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
taietel Posted August 5, 2011 Posted August 5, 2011 Regarding array of buttons, here is another version: expandcollapse popupGUICreate("Button Array", 400,500) $aB = _ButtonsArray(390,490,5,5,7) For $i=0 To UBound($aB)-1 GUICtrlSetData($aB[$i], $i) Next GUISetState() While 1 Sleep(10) $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit Case $aB[0] To $aB[UBound($aB)-1] $lCtrlId = GUIGetCursorInfo() For $i=0 To UBound($aB)-1 If $aB[$i]=$lCtrlId[4] Then MsgBox(0,"You clicked on","Button no."&$i) Next EndSwitch WEnd Func _ButtonsArray($iW=200, $iH=200, $iX=5, $iY=5, $iButton=3) Local $iGap=5, $aButtons[$iButton^2] Local $w = Ceiling(($iW-$iGap*($iButton+1))/$iButton) Local $h = Ceiling(($iH-$iGap*($iButton+1))/$iButton) If $w<20 or $h<20 Then MsgBox(0,"Neah...","Try a bigger value!...") Return EndIf For $i=0 To $iButton-1 For $j=0 To $iButton-1 $aButtons[$j+$i*$iButton]= GUICtrlCreateButton("",$iX + $j*($w+$iGap), $iY + $i*($h+$iGap), $w, $h) Next Next Return $aButtons EndFunc Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
monoscout999 Posted August 5, 2011 Posted August 5, 2011 @taitel I edit your version. The loop partGUICreate("Button Array", 400, 500) $aB = _ButtonsArray(390, 490, 5, 5, 7) For $i = 0 To UBound($aB) - 1 GUICtrlSetData($aB[$i], $i) Next GUISetState() While 1 Sleep(10) $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit Case $aB[0] To $aB[UBound($aB) - 1] For $i = 0 To UBound($aB) - 1 If $nmsg = $aB[$i] Then MsgBox(0, "You clicked on", "Button no." & $i) Next EndSwitch WEnd Func _ButtonsArray($iW = 200, $iH = 200, $iX = 5, $iY = 5, $iButton = 3) Local $iGap = 5, $aButtons[$iButton ^ 2] Local $w = Ceiling(($iW - $iGap * ($iButton + 1)) / $iButton) Local $h = Ceiling(($iH - $iGap * ($iButton + 1)) / $iButton) If $w < 20 Or $h < 20 Then MsgBox(0, "Neah...", "Try a bigger value!...") Return EndIf For $i = 0 To $iButton - 1 For $j = 0 To $iButton - 1 $aButtons[$j + $i * $iButton] = GUICtrlCreateButton("", $iX + $j * ($w + $iGap), $iY + $i * ($h + $iGap), $w, $h) Next Next Return $aButtons EndFunc ;==>_ButtonsArray
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now