Jump to content
Sign in to follow this  
CannonFoddr

Show/Hide Multiple components

Recommended Posts

CannonFoddr

Ok - a bit of background info first ..

I'm new to AutoIt (been experimenting for about a week) but I have had a small bit of (self taught) experience many years ago (~20yr) with Delphi - so not too unfamiliar with programming, it's just a case of learning a 'new language' & the 'quirks'/'commands' it uses

Now the 'problem'..

I've had an idea for an App that required certain controls to appear depending on what you want to do (but keeping an Image in place all the time on the right) & I decided that the best way is to show the required controls based on what been selected in a Dropdown box (& suprizingly I have actually got it to work - nearly)

[i would've Used 'Tabs' but there's really to many items to have on tabs - ~25 items)

Some of the components are a combination of Label,Inputbox and UpDown spinboxes (In Delphi such 'group' would be all one component, In AutoIt it's classed/created as 3 seperate Items it seems - One of the 'quirks' I've discovered so far)

Now I've figured out that I need to use 'ControlHide' and 'Controlshow' to hide/show components, but since I need to 'hide' anything up to 8 spinbox combo's (a 'Combo' is Label/inputbox/Spinbox remember) - that means I'd need ~24lines of code just to hide them all

I was wondering - Is there an simpler,better(i.e shorter) way of hiding a group of components in just one command or something ?? (I've have tried 'grouping' them together & then hiding just the 'group' but that doesn't seem to work - which In Delphi did work)

For example if I have a Combo of '$Xpos_Label','$Xpos_Input' and '$XPos_UpDown' - is there a way to hide all 3 in one go instead of writing 3 lines of code with 'Controlhide' for each ??

The only other way I can think of it is to have an array & using a For..Next loop e.g '$Component(1) = $Xpos_Label','$Component(2) = $Xpos_Input' etc etc then having 'For loop = 1 to ...' / 'ControlHide( "","",$Component(loop))' / 'Next loop'

Any help to an 'old boy new to AutoIt' apreciated

Share this post


Link to post
Share on other sites
Melba23

CannonFoddr,

Welcome to the AutoIt forum. :idea:

You cannot hide multiple controls in one command, but as you suspected you can use a little trick to use a small loop - only 3 lines. :(

When AutoIt creates commands it allocates each one a ControlID. Basically these ControlIDs are the index number of an internal AutoIt array which holds the "real" ID (handle) of the control. AutoIt allocates these in strict numerical order, so if you create the controls in immediate succession,, you get consecutive numbers. Can you see where this is going yet?

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hLabel = GUICtrlCreateLabel("Label", 10, 10, 50, 20)
$hInput = GUICtrlCreateInput("", 10, 30, 100, 20)
GUICtrlCreateUpdown($hInput)

$hButton = GUICtrlCreateButton("Hide", 10, 100, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            If GUICtrlRead($hButton) = "Hide" Then
                GUICtrlSetData($hButton, "Show")
                For $i = $hLabel To $hLabel + 2
                    GUICtrlSetState($i, $GUI_HIDE)
                Next
            Else
                GUICtrlSetData($hButton, "Hide")
                For $i = $hLabel To $hLabel + 2
                    GUICtrlSetState($i, $GUI_SHOW)
                Next
            EndIf
    EndSwitch

WEnd

But this trick only works if the controls are created in immediate succession. And if you have already deleted any previouly created controls, leaving blanks in the array, AutoIt will fill those first - so you might not get successive numbers even though the controls were created one after the other. You need to take care - but the trick does work very well. :)

M23

Edit: Typnig!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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
CannonFoddr

Many thanks for that little titbit of info

- Seems like I had the right idea all along, just didn't know about the ControlID's

Anyway, I've altered my little test project using this tip - Still works how I wanted it and also reduced the listing by ~20Lines

Not much - but every little bit (or would that be 'byte'? :idea: ) helps

Share this post


Link to post
Share on other sites
Melba23

CannonFoddr,

just didn't know about the ControlID's

That what you get returned when you create a control and use to identify the control in any subsequent code: :idea:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)
; $hButton is the ControlId

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton ; The ControlID is used here
            MsgBox(0, "ControlID", "The ControlID of the button is " & $hButton)
    EndSwitch

WEnd

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

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  

×