Jewtus

Gui slider for display/hide elements in a tab

5 posts in this topic

I have a pretty complicated GUI that has 11 tabs and each tab has a series or questions associated with each tab. Some of the tabs only have a few questions but others have 10+ questions which don't really fit well into any GUI (unless I give them no space to respond). So what I did was put all the elements on top of each other and used $GUI_HIDE and $GUI_SHOW to toggle the visible fields based on the current slider selection. Here is an excerpt:

Case $idLandRSlider
                GUISetState(@SW_LOCK)
                If GUICtrlRead($idLandRSlider)=0 Then
                    GuiCtrlSetState($lab6_1,$GUI_SHOW)
                    GuiCtrlSetState($id6_1,$GUI_SHOW)
                    GuiCtrlSetState($id6_2,$GUI_SHOW)
                    GuiCtrlSetState($lab6_2,$GUI_SHOW)
                    GuiCtrlSetState($id6_3,$GUI_SHOW)
                    GuiCtrlSetState($lab6_3,$GUI_SHOW)
                    GuiCtrlSetState($lab6_4,$GUI_SHOW)
                    GuiCtrlSetState($id6_4Yes,$GUI_SHOW)
                    GuiCtrlSetState($id6_4No,$GUI_SHOW)
                    GuiCtrlSetState($lab6_5,$GUI_SHOW)
                    GuiCtrlSetState($id6_5Yes,$GUI_SHOW)
                    GuiCtrlSetState($id6_5No,$GUI_SHOW)
                    GuiCtrlSetState($lab6_6,$GUI_HIDE)
                    GuiCtrlSetState($id6_6Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_6No,$GUI_HIDE)
                    GuiCtrlSetState($id6_6,$GUI_HIDE)
                    GuiCtrlSetState($lab6_6b,$GUI_HIDE)
                    GuiCtrlSetState($id6_6bYes,$GUI_HIDE)
                    GuiCtrlSetState($id6_6bNo,$GUI_HIDE)
                    GuiCtrlSetState($lab6_6c,$GUI_HIDE)
                    GuiCtrlSetState($id6_7_8,$GUI_HIDE)
                    GuiCtrlSetState($lab6_7,$GUI_HIDE)
                    GuiCtrlSetState($lab6_8,$GUI_HIDE)
                    GuiCtrlSetState($lab6_7_8,$GUI_HIDE)
                    GuiCtrlSetState($id6_7Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_7No,$GUI_HIDE)
                    GuiCtrlSetState($id6_8Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_8No,$GUI_HIDE)
                    GuiCtrlSetState($lab6_9,$GUI_HIDE)
                    GuiCtrlSetState($id6_9Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_9No,$GUI_HIDE)
                    GuiCtrlSetState($id6_9,$GUI_HIDE)
                    GuiCtrlSetState($lab6_9b,$GUI_HIDE)
                    GuiCtrlSetState($lab6_10,$GUI_HIDE)
                    GuiCtrlSetState($id6_10,$GUI_HIDE)
                    GuiCtrlSetState($lab6_11,$GUI_HIDE)
                    GuiCtrlSetState($id6_11Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_11No,$GUI_HIDE)
                    GuiCtrlSetState($id6_11,$GUI_HIDE)
                    GuiCtrlSetState($lab6_11b,$GUI_HIDE)
                    GuiCtrlSetState($id6_11bYes,$GUI_HIDE)
                    GuiCtrlSetState($id6_11bNo,$GUI_HIDE)
                    GuiCtrlSetState($lab6_11c,$GUI_HIDE)
                    GuiCtrlSetState($lab6_12,$GUI_HIDE)
                    GuiCtrlSetState($id6_12Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_12No,$GUI_HIDE)
                    GuiCtrlSetState($id6_12,$GUI_HIDE)
                    GuiCtrlSetState($lab6_12b,$GUI_HIDE)
                ElseIf GUICtrlRead($idLandRSlider)=1 Then
                    GuiCtrlSetState($lab6_1,$GUI_HIDE)
                    GuiCtrlSetState($id6_1,$GUI_HIDE)
                    GuiCtrlSetState($id6_2,$GUI_HIDE)
                    GuiCtrlSetState($lab6_2,$GUI_HIDE)
                    GuiCtrlSetState($id6_3,$GUI_HIDE)
                    GuiCtrlSetState($lab6_3,$GUI_HIDE)
                    GuiCtrlSetState($lab6_4,$GUI_HIDE)
                    GuiCtrlSetState($id6_4Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_4No,$GUI_HIDE)
                    GuiCtrlSetState($id6_4,$GUI_HIDE)
                    GuiCtrlSetState($lab6_5,$GUI_HIDE)
                    GuiCtrlSetState($id6_5Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_5No,$GUI_HIDE)
                    GuiCtrlSetState($lab6_5b,$GUI_HIDE)
                    GuiCtrlSetState($id6_5Law,$GUI_HIDE)
                    GuiCtrlSetState($id6_5Contract,$GUI_HIDE)
                    GuiCtrlSetState($lab6_5c,$GUI_HIDE)
                    GuiCtrlSetState($id6_5cYes,$GUI_HIDE)
                    GuiCtrlSetState($id6_5cNo,$GUI_HIDE)
                    GuiCtrlSetState($id6_5,$GUI_HIDE)
                    GuiCtrlSetState($lab6_5d,$GUI_HIDE)
                    GuiCtrlSetState($lab6_6,$GUI_SHOW)
                    GuiCtrlSetState($id6_6Yes,$GUI_SHOW)
                    GuiCtrlSetState($id6_6No,$GUI_SHOW)
                    GuiCtrlSetState($lab6_7,$GUI_SHOW)
                    GuiCtrlSetState($lab6_8,$GUI_SHOW)
                    GuiCtrlSetState($id6_7Yes,$GUI_SHOW)
                    GuiCtrlSetState($id6_7No,$GUI_SHOW)
                    GuiCtrlSetState($id6_8Yes,$GUI_SHOW)
                    GuiCtrlSetState($id6_8No,$GUI_SHOW)
                    GuiCtrlSetState($lab6_9,$GUI_SHOW)
                    GuiCtrlSetState($id6_9Yes,$GUI_SHOW)
                    GuiCtrlSetState($id6_9No,$GUI_SHOW)
                    GuiCtrlSetState($lab6_10,$GUI_SHOW)
                    GuiCtrlSetState($id6_10,$GUI_SHOW)
                    GuiCtrlSetState($lab6_11,$GUI_HIDE)
                    GuiCtrlSetState($id6_11Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_11No,$GUI_HIDE)
                    GuiCtrlSetState($id6_11,$GUI_HIDE)
                    GuiCtrlSetState($lab6_11b,$GUI_HIDE)
                    GuiCtrlSetState($id6_11bYes,$GUI_HIDE)
                    GuiCtrlSetState($id6_11bNo,$GUI_HIDE)
                    GuiCtrlSetState($lab6_11c,$GUI_HIDE)
                    GuiCtrlSetState($lab6_12,$GUI_HIDE)
                    GuiCtrlSetState($id6_12Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_12No,$GUI_HIDE)
                    GuiCtrlSetState($id6_12,$GUI_HIDE)
                    GuiCtrlSetState($lab6_12b,$GUI_HIDE)
                ElseIf GUICtrlRead($idLandRSlider)=2 Then
                    GuiCtrlSetState($lab6_1,$GUI_HIDE)
                    GuiCtrlSetState($id6_1,$GUI_HIDE)
                    GuiCtrlSetState($id6_2,$GUI_HIDE)
                    GuiCtrlSetState($lab6_2,$GUI_HIDE)
                    GuiCtrlSetState($id6_3,$GUI_HIDE)
                    GuiCtrlSetState($lab6_3,$GUI_HIDE)
                    GuiCtrlSetState($lab6_4,$GUI_HIDE)
                    GuiCtrlSetState($id6_4Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_4No,$GUI_HIDE)
                    GuiCtrlSetState($id6_4,$GUI_HIDE)
                    GuiCtrlSetState($lab6_5,$GUI_HIDE)
                    GuiCtrlSetState($id6_5Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_5No,$GUI_HIDE)
                    GuiCtrlSetState($lab6_5b,$GUI_HIDE)
                    GuiCtrlSetState($id6_5Law,$GUI_HIDE)
                    GuiCtrlSetState($id6_5Contract,$GUI_HIDE)
                    GuiCtrlSetState($lab6_5c,$GUI_HIDE)
                    GuiCtrlSetState($id6_5cYes,$GUI_HIDE)
                    GuiCtrlSetState($id6_5cNo,$GUI_HIDE)
                    GuiCtrlSetState($id6_5,$GUI_HIDE)
                    GuiCtrlSetState($lab6_5d,$GUI_HIDE)
                    GuiCtrlSetState($lab6_6,$GUI_HIDE)
                    GuiCtrlSetState($id6_6Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_6No,$GUI_HIDE)
                    GuiCtrlSetState($lab6_7,$GUI_HIDE)
                    GuiCtrlSetState($lab6_8,$GUI_HIDE)
                    GuiCtrlSetState($id6_7Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_7No,$GUI_HIDE)
                    GuiCtrlSetState($id6_8Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_8No,$GUI_HIDE)
                    GuiCtrlSetState($lab6_9,$GUI_HIDE)
                    GuiCtrlSetState($id6_9Yes,$GUI_HIDE)
                    GuiCtrlSetState($id6_9No,$GUI_HIDE)
                    GuiCtrlSetState($lab6_10,$GUI_HIDE)
                    GuiCtrlSetState($id6_10,$GUI_HIDE)
                    GuiCtrlSetState($lab6_11,$GUI_SHOW)
                    GuiCtrlSetState($id6_11Yes,$GUI_SHOW)
                    GuiCtrlSetState($id6_11No,$GUI_SHOW)
                    GuiCtrlSetState($lab6_12,$GUI_SHOW)
                    GuiCtrlSetState($id6_12Yes,$GUI_SHOW)
                    GuiCtrlSetState($id6_12No,$GUI_SHOW)
                EndIf
                GUISetState(@SW_UNLOCK)

I was thinking about building a ternary operator function to toggle, but in order to do that I need to declare the variables as global to pass out of the GUI function into the other function, or pass the labels/entry boxes into the functions... which given the number of elements, is out of the question.

 

Can anyone think of a better way of doing this? I have about 600 lines just doing the GUI show/hide stuff and I'd like to make it a little more compact/efficient.

Share this post


Link to post
Share on other sites



Jewtus,

Use a child window in each tab with a scrollbar - than all the questions are visible all the time and all you need to do is manage the visible child. I will try and provide an example later.

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

Jewtus,

An example - you will need a couple of my UDFs which you can find in my sig:

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

#include "GUIScrollbars_Ex.au3"
#include "StringSize.au3"

; Array to hold child GUI handles
Global $aChildren[3]

; Create main GUI
$hGUI = GUICreate("Test", 500, 500)

$cTab = GUICtrlCreateTab(10, 10, 480, 400)
$cTab_0 = GUICtrlCreateTabItem("Tab 0")
$cTab_1 = GUICtrlCreateTabItem("Tab 1")
$cTab_2 = GUICtrlCreateTabItem("Tab 2")
GUICtrlCreateTabItem("")

GUISetState()

; Create children
$aChildren[0] = GUICreate("", 440, 340, 30, 50, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xFFCCCC, $aChildren[0])

; Data for this GUI
$sData = "Just a single line in this GUI"
$aSize = _StringSize($sData)                        ; Get required depth
GUICtrlCreateLabel($sData, 10, 10, 420, $aSize[3])  ; Size label accordingly
GUICtrlSetBkColor(-1, 0xFEFEFE)

; Show child
GUISetState()

; Create scrollbars if needed
If $aSize[3] > 340 Then
    _GUIScrollbars_Generate($aChildren[0], 0, $aSize[3] + 20)
EndIf

$aChildren[1] = GUICreate("", 440, 340, 30, 50, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xCCFFCC, $aChildren[1])

$sData = ""
For $i = 0 To 200
    $sData &= "Line " & $i & @CRLF
Next
$aSize = _StringSize($sData)
GUICtrlCreateLabel($sData, 10, 10, 420, $aSize[3])
GUICtrlSetBkColor(-1, 0xFEFEFE)

GUISetState(@SW_HIDE, $aChildren[1])

If $aSize[3] > 340 Then
    _GUIScrollbars_Generate($aChildren[1], 0, $aSize[3] + 20)
EndIf

$aChildren[2] = GUICreate("", 440, 340, 30, 50, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xCCCCFF, $aChildren[2])

$sData = ""
For $i = 0 To 50
    $sData &= "Line " & $i & @CRLF
Next
$aSize = _StringSize($sData)
GUICtrlCreateLabel($sData, 10, 10, 420, $aSize[3])
GUICtrlSetBkColor(-1, 0xFEFEFE)

GUISetState(@SW_HIDE, $aChildren[2])

_GUIScrollbars_Generate($aChildren[2], 0, $aSize[3] + 20)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cTab
            ; Hide/show children depending on tab selected
            For $i = 0 To 2
                GUISetState(@SW_HIDE, $aChildren[$i])
            Next
            GUISetState(@SW_SHOW, $aChildren[GUICtrlRead($cTab)])
    EndSwitch

WEnd

I hope the comments are clear enough, but do ask if not.

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

Oh, I gotcha. I like it. I'll see if I can adapt it to what I'm doing. Right now my tool is in a constant state of flux (because my manager hasn't defined the actual requirements) but this would be great for the final version.

 

Thanks!

Share this post


Link to post
Share on other sites

Jewtus,

Delighted you like it. Obviously you could get a lot of the repetitive code into functions - let me know if I can help in any way.

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

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