Sign in to follow this  
Followers 0
Goon

Reload Refresh GUI after Gui Input

3 posts in this topic

I was having a problem resizing a GUI based on the input within the GUI in a project I'm working on.

In writing an example to post here, I sort of solved my problem, but would like to know if there is a better way to do this as it creates some interesting problems within my project.

Basically, I want the form to resize based on the number of lines I wish to display. I am purposely avoiding the use of scrollbars, but want to keep the form size to a minimum.

Complications that may arise within my project are the fact that values posted into inputs(not shown here) are read from a file, including the initial value for $lines.

In the absence of a GUIReload, is there a better way to handle this?

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $Input1
Global $lines = InputBox("Testing", "Enter number of lines to display.", "", " M2")

doit($lines)
Func doit($lines)
if $lines = 0 or $lines > 10 Then
    msgbox(4096,"Error", "Input not correct, Defaulting to 2 lines",0)
    $lines = 2
EndIf
$size = 20
$incr = 20
$Form1 = GUICreate("Form1", 176, 50 + $size * $lines, 192, 124)
if $lines >= 1 then
$Label1 = GUICtrlCreateLabel("Label1", 64, $size, 36, 17)
$size= $size + $incr
EndIf
if $lines >= 2 then
$Label2 = GUICtrlCreateLabel("Label2", 64, $size, 36, 17)
$size= $size + $incr
EndIf
if $lines >= 3 then
$Label3 = GUICtrlCreateLabel("Label3", 64, $size, 36, 17)
$size= $size + $incr
EndIf
if $lines >= 4 then
    $Label4 = GUICtrlCreateLabel("Label4", 64, $size, 36, 17)
$size= $size + $incr
EndIf
if $lines >= 5 then
    $Label5 = GUICtrlCreateLabel("Label5", 64, $size, 36, 17)
$size= $size + $incr
EndIf
if $lines >= 6 then
    $Label6 = GUICtrlCreateLabel("Label6", 64, $size, 36, 17)
$size= $size + $incr
EndIf
if $lines >= 7 then
    $Label7 = GUICtrlCreateLabel("Label7", 64, $size, 36, 17)
$size= $size + $incr
EndIf
if $lines >= 8 then
    $Label8 = GUICtrlCreateLabel("Label8", 64, $size, 36, 17)
$size= $size + $incr
EndIf
if $lines >= 9 then
    $Label9 = GUICtrlCreateLabel("Label9", 64, $size, 36, 17)
$size= $size + $incr
EndIf


$Input1 = GUICtrlCreateInput($lines, 10, 16, 41, 21)
GUICtrlSetTip(-1, " Select number of lines to display and press Enter")
GUISetState(@SW_SHOW)

EndFunc
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Input1
            $y1 = GUICtrlRead($Input1)
            GUIDelete()
            doit($y1)

    EndSwitch
WEnd

Yes, I am a self taught programmer, so any streamlining of any of my code would not insult me. :blink:

As a side issue, with all my if statements, is there a way to auto increment variable names so I could do something like this:

Note. This code doesn't work. Basically I want it to loop through 5 times and create 5 lines with 5 different control names.
$lines = 5
$cnt = 1
do
if $lines >= $cnt then  ;<<Probably superfluous in this
$Label&cnt = GUICtrlCreateLabel("Label"&cnt, 64, $size, 36, 17)
$size= $size + $incr
EndIf    ;<<also not required
$cnt = $cnt + 1
until $lines = $cnt

Share this post


Link to post
Share on other sites



Goon,

Welcome to the AutoIt forum. :blink:

Yuo need to learn about arrays! :

You can make your code much shorter and answer your second question in one go: ;)

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Input1, $size = 20, $aLabel_ID[1] ; Create label to hold number of lines and their ControlIDs
$aLabel_ID[0] = InputBox("Testing", "Enter number of lines to display.", "", " M2")

; Create the GUI once
$Form1 = GUICreate("Form1", 176, 50 + $size * $aLabel_ID[0], 192, 124)
$Input1 = GUICtrlCreateInput($aLabel_ID[0], 10, 16, 41, 21)
GUICtrlSetTip(-1, " Select number of lines to display and press Enter")
GUISetState(@SW_SHOW)

doit()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Input1
            ; Delete current labels
            For $i = 1 To $aLabel_ID[0]
                GUICtrlDelete($aLabel_ID[$i])
            Next
            ; Get new value
            $aLabel_ID[0] = GUICtrlRead($Input1)
            doit()
    EndSwitch
WEnd

Func doit()

    If $aLabel_ID[0] = 0 Or $aLabel_ID[0] > 10 Then
        MsgBox(4096, "Error", "Input not correct, Defaulting to 2 lines", 0)
        $aLabel_ID[0] = 2
    EndIf
    ; Resize the GUI
    WinMove($Form1, "", 192, 124, 176, 50 + $size * $aLabel_ID[0])
    ; Get array to correct size
    ReDim $aLabel_ID[$aLabel_ID[0] + 1]
    ; Loop to create the labels
    For $i = 1 To $aLabel_ID[0]
        ; Store the ControlIDs in the array
        $aLabel_ID[$i] = GUICtrlCreateLabel("Label " & $i, 64, $i * $size, 36, 17)
    Next
    
EndFunc   ;==>doit

Please ask if anything is unclear. :P

M23


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

Please ask if anything is unclear. :blink:

Thats clear as Glass.

Winmove replacing my delete and reload

And the arrays are perfect.

Bound to bring me more problems while I convert 400 lines of code down to 100, but many thanks for your prompt response and solution.

Cheers

Goon

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  
Followers 0