CannonFoddr Posted April 25, 2010 Share Posted April 25, 2010 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 25, 2010 Moderators Share Posted April 25, 2010 (edited) CannonFoddr,Welcome to the AutoIt forum. 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 WEndBut 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. M23Edit: Typnig! Edited April 25, 2010 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
CannonFoddr Posted April 25, 2010 Author Share Posted April 25, 2010 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'? ) helps Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 25, 2010 Moderators Share Posted April 25, 2010 CannonFoddr, just didn't know about the ControlID'sThat what you get returned when you create a control and use to identify the control in any subsequent code: #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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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