Jump to content
Sign in to follow this  
Realm

[Solved] how to activate/hide tabs with radio buttons

Recommended Posts

Realm

How do I activate or hide particular tabs with radio buttons?

What I'd like to do is if Radio1 is pressed than only tabsheet1 will show

if Radio2 then only tabsheet 2

if Radio3 then both tabsheet 1 and tabsheet 2

if Radio4 then tabsheet 3

#include <GUIConstantsEx.au3>

$gui = GUICreate("test",450, 300)
$Radio1 = GUICtrlCreateRadio("Radio1", 32, 250, 60, 17)
$Radio2 = GUICtrlCreateRadio("Radio2", 32, 274, 57, 17)
$Radio3 = GUICtrlCreateRadio("Radio3", 112, 250, 113, 17)
$Radio4 = GUICtrlCreateRadio("Radio4", 112, 274, 97, 17)


$Tab1 = GUICtrlCreateTab(20, 24, 425, 201)
$TabSheet1 = GUICtrlCreateTabItem("Tabsheet 1")
$TabSheet2 = GUICtrlCreateTabItem("Tabsheet 2")
$TabSheet3 = GUICtrlCreateTabItem("Tabsheet 3")

GUISetState()
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Thanks in advance

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites
Melba23

Realm,

I do not believe you can disable (or hide) tabs. :(

But you can prevent them from being selected like this: :)

#include <GUIConstantsEx.au3>

; Array to hold tab allowed state
Global $afTabSheets[3] = [True, False, False]

$gui = GUICreate("test",450, 300)

GUIStartGroup()
$Radio1 = GUICtrlCreateRadio("Radio1", 32, 250, 100, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio2 = GUICtrlCreateRadio("Radio2", 32, 274, 100, 17)
$Radio3 = GUICtrlCreateRadio("Radio3", 152, 250, 100, 17)
$Radio4 = GUICtrlCreateRadio("Radio4", 152, 274, 100, 17)
GUIStartGroup()

$Tab1 = GUICtrlCreateTab(20, 24, 425, 201)
$TabSheet1 = GUICtrlCreateTabItem("Tabsheet 1")
$TabSheet2 = GUICtrlCreateTabItem(" ")
$TabSheet3 = GUICtrlCreateTabItem(" ")

GUISetState()

$iCurrRadio = 0

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Tab1
            ; If tab clicked, check if tab valid
            $iTabSel = GUICtrlRead($Tab1)
            ; Ensure valid tab displayed
            If $afTabSheets[$iTabSel] = False Then
                _Sel_Tab()
            EndIf

    EndSwitch

    ; Check if radios altered
    For $i = 0 To 4
        If GUICtrlRead($Radio1 + $i) = 1 Then ExitLoop
    Next
    If $i <> $iCurrRadio Then
        ; Change reference value
        $iCurrRadio = $i
        ; Set tab state array as required
        Switch $i
            Case 0 ; Radio 1
                $afTabSheets[0] = True
                GUICtrlSetData($TabSheet1, "Tabsheet 1")
                $afTabSheets[1] = False
                GUICtrlSetData($TabSheet2, " ")
                $afTabSheets[2] = False
                GUICtrlSetData($TabSheet3, " ")
            Case 1 ; Radio 2
                $afTabSheets[0] = False
                GUICtrlSetData($TabSheet1, " ")
                $afTabSheets[1] = True
                GUICtrlSetData($TabSheet2, "Tabsheet 2")
                $afTabSheets[2] = False
                GUICtrlSetData($TabSheet3, " ")
            Case 2 ; Radio 3
                $afTabSheets[0] = True
                GUICtrlSetData($TabSheet1, "Tabsheet 1")
                $afTabSheets[1] = True
                GUICtrlSetData($TabSheet2, "Tabsheet 2")
                $afTabSheets[2] = False
                GUICtrlSetData($TabSheet3, " ")
            Case 3 ; Radio 4
                $afTabSheets[0] = False
                GUICtrlSetData($TabSheet1, " ")
                $afTabSheets[1] = False
                GUICtrlSetData($TabSheet2, " ")
                $afTabSheets[2] = True
                GUICtrlSetData($TabSheet3, "Tabsheet 3")
        EndSwitch
        ; Ensure valid tab displayed
        _Sel_Tab()

    EndIf


WEnd

Func _Sel_Tab()

    ; Show first valid tab
    For $i = 0 To 3
        If $afTabSheets[$i] = True Then
            GUICtrlSetState($TabSheet1 + $i, $GUI_SHOW)
            Return
        EndIf
    Next

EndFunc

I hope that helps. :idea:

M23

Edit: Found Funkey's OwnTab UDF which might help as apparently it can disable the tabs it creates. :)

Edited by Melba23

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
Realm

Edit: Found Funkey's OwnTab UDF which might help as apparently it can disable the tabs it creates. :idea:

Just Fabulous, a perfect solution, thanks for pointing it out, I also left a comment on his thread as well!

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

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  

×