Jump to content
Sign in to follow this  
smashly

[Question]Auto resize GUI to fit added Controls?

Recommended Posts

smashly

Hi to all and thank for reading my first post in this forum.

Hoping that my beggings are simple.

I'm not actually writing anything for a purpose yet and I'm slowly trying to wrap my mind around AutoIt and what can be done with it's GUI.

Could someone please post or point me to a small sample of how to get a Gui to Auto Resize by an added Control?

eg:

#include <GUIConstants.au3>


GUICreate("Main",80,40,-1,-1)  
GUISetState (@SW_SHOW)     
Opt("GUICoordMode", 2)

$Button = GUICtrlCreateButton ("Add",-1,-1,40,40)
GUICtrlSetResizing ($Button,$GUI_DOCKLEFT+$GUI_DOCKVCENTER)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $Button Then
                   $Button1 = GUICtrlCreateButton ("Newer",0,-1)
    EndIf
Wend

Basicly I'm after when a button is added to the Main window that the Main window resizes to fit the new button added. (please forgive my bad non working example above :"> ).

In the meantime I'll keep sifting through the AutoIt forum and Help files and such to better my understanding. So far AutoIts help files have been an absolute blessing and a half,

now if I coulkd just get my mind around that bundle of info. :D

Thank You

&

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites
Uten

Somthing like this?

#include <GUIConstants.au3>


$gForm = GUICreate("Main",80,40,-1,-1)  
GUISetState (@SW_SHOW)      
Opt("GUICoordMode", 2)
Global $Buttons[10]

$Buttons[1] = GUICtrlCreateButton ("Add",-1,-1,40,40)
$Buttons[0] = 1
GUICtrlSetResizing($Buttons[$Buttons[0]], $GUI_DOCKSIZE+ $GUI_DOCKLEFT)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    for $i = 1 to $Buttons[0]
      If $msg = $Buttons[$i] Then
         $Buttons[$Buttons[0]+1] = GUICtrlCreateButton ("Newer:" & $Buttons[0]+1,0,-1)
         $Buttons[0] =$Buttons[0] + 1 
         GUICtrlSetResizing($Buttons[$Buttons[0]], $GUI_DOCKSIZE + $GUI_DOCKLEFT)
         ; get last possition
         $SC =WinGetPos(GuiCtrlGetHandle($Buttons[$Buttons[0]]))
         ConsoleWrite("$SC[0]:=" & $SC[0] & ", $SC[1]:=" & $SC[1] & ", $SC[2]:=" & $SC[2] & ", $SC[3]:=" & $SC[3] & @LF)
         ;Resize form
         $SF = WinGetPos(WinGetHandle($gForm))
         ConsoleWrite("$SF[0]:=" & $SF[0] & ", $SF[1]:=" & $SF[1] & ", $SF[2]:=" & $SF[2] & ", $SF[3]:=" & $SF[3] & @LF)
         WinMove(WinGetHandle($gForm),"", $SF[0], $SF[1], $SC[0] -$SF[0] + $SC[2] + 10)        
      EndIf
   Next 
Wend

Share this post


Link to post
Share on other sites
smashly

Thank You for taking the time Uten. It's greatly appreciated.

Sorry to say I get an Undefined Function error when I tried your updated code.

C:\Temp\testresizeaddcontrol.au3(23,63) : ERROR: GuiCtrlGetHandle(): undefined function.

$SC =WinGetPos(GuiCtrlGetHandle($Buttons[$Buttons[0]])

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

What am I doing wrong? Edited by smashly

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
smashly

Thank You , dang that's just nifty .. my fondness of AutoIt has become even more so now :D

Once again

Thank You Uten

& Cheers SmOke_N

All Good :D

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
Sign in to follow this  

×