Jump to content

How do I switch the StatusBar depending on which tab is in focus?


guwguw
 Share

Recommended Posts

When using multiple tabs, I am not capable to make the status bar information change accordingly.

Based on Autoit's help system's GUICtrlCreateTab example I tried the following

#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <Date.au3>

Example()

Func Example()
    Local $msg, $StatusBar1
    Local $a_PartsRightEdge[5] = [50, 150, 220, 280, 300]
    Local $a_PartsText[5] = [" Info", "Details", "some data", _NowCalcDate(), " date+5= " & _DateAdd('d', 5, _NowCalcDate())]
    $topWindow = GUICreate("My GUI Tab") ; will create a dialog box that when displayed is centered

    GUISetBkColor(0x00E0FFFF)
    GUISetFont(9, 300)

    $tab0 = GUICtrlCreateTab(10, 10, 200, 100)

    GUICtrlCreateTabItem("tab0")
    GUICtrlCreateLabel("label0", 30, 80, 50, 20)
    GUICtrlCreateButton("OK0", 20, 50, 50, 20)
    GUICtrlCreateInput("default", 80, 50, 70, 20)

    $tab1 = GUICtrlCreateTabItem("tab----1")
    GUICtrlCreateLabel("label1", 30, 80, 50, 20)
    GUICtrlCreateCombo("", 20, 50, 60, 120)
    GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon") ; default Jon
    GUICtrlCreateButton("OK1", 80, 50, 50, 20)

    $tab2 = GUICtrlCreateTabItem("tab2")
    GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
    GUICtrlCreateLabel("label2", 30, 80, 50, 20)
    GUICtrlCreateButton("OK2", 140, 50, 50)

    GUICtrlCreateTabItem("") ; end tabitem definition

    GUICtrlCreateLabel("label3", 20, 130, 50, 20)

    GUISetState()

    $StatusBarmain = _GUICtrlStatusBar_Create($topWindow, $a_PartsRightEdge, $a_PartsText)
    $StatusBar0 = _GUICtrlStatusBar_Create($tab0, $a_PartsRightEdge, $a_PartsText)
    $StatusBar1 = _GUICtrlStatusBar_Create($tab1, $a_PartsRightEdge, $a_PartsText)
    $StatusBar2 = _GUICtrlStatusBar_Create($tab2, $a_PartsRightEdge, $a_PartsText)
    _GUICtrlStatusBar_SetText($tab0, "Part 0", 2)
    _GUICtrlStatusBar_SetText($tab1, "Part 11", 2)
    _GUICtrlStatusBar_SetText($tab2, "Part 222", 2)

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>Example

What is the proper way of changing the bar text when the new tab gets focus? (if there is any, lol)

Currently, only the $StatusBarmain can be altered ...

Edited by guwguw
Link to comment
Share on other sites

  • Moderators

guwguw,

You cannot have a statusbar inside each tab - they are not GUIs. But you could have a child GUI just underneath the tab and show the statusbar associated with the selected tab like this: ;)

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

Example()

Func Example()
    Local $msg, $StatusBar1

    $topWindow = GUICreate("My GUI Tab", 500, 500) ; will create a dialog box that when displayed is centered

    GUISetBkColor(0x00E0FFFF)
    GUISetFont(9, 300)

    $cTab = GUICtrlCreateTab(10, 10, 480, 200)

    $tab0 = GUICtrlCreateTabItem("Tab 0")
    GUICtrlCreateLabel("label0", 30, 80, 50, 20)
    GUICtrlCreateButton("OK0", 20, 50, 50, 20)
    GUICtrlCreateInput("default", 80, 50, 70, 20)

    $tab1 = GUICtrlCreateTabItem("tab 1")
    GUICtrlCreateLabel("label1", 30, 80, 50, 20)
    GUICtrlCreateCombo("", 20, 50, 60, 120)
    GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon") ; default Jon
    GUICtrlCreateButton("OK1", 80, 50, 50, 20)

    $tab2 = GUICtrlCreateTabItem("Tab 2")
    GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
    GUICtrlCreateLabel("label2", 30, 80, 50, 20)
    GUICtrlCreateButton("OK2", 140, 50, 50)

    GUICtrlCreateTabItem("") ; end tabitem definition

    Local $a_PartsRightEdge[5] = [50, 150, 220, 300, 300]
    Local $a_PartsText[5] = [" Info", "Details", "some data", _NowCalcDate(), " date+5= " & _DateAdd('d', 5, _NowCalcDate())]
    $StatusBarmain = _GUICtrlStatusBar_Create($topWindow, $a_PartsRightEdge, $a_PartsText)

    GUISetState()

    $hGUI_tab = GUICreate("Tab status", 476, 20, 0, 0, BitOr($WS_BORDER, $WS_POPUP), $WS_EX_MDICHILD, $topWindow)
    GUISetBkColor(0xFF0000)
    $aMain_Pos = WinGetPos($topWindow)
    WinMove($hGUI_tab, "", $aMain_Pos[0] + 13, $aMain_Pos[1] + 232)
    GUISetState()


    $StatusBar0 = _GUICtrlStatusBar_Create($hGUI_tab, $a_PartsRightEdge, $a_PartsText)
    $StatusBar1 = _GUICtrlStatusBar_Create($hGUI_tab, $a_PartsRightEdge, $a_PartsText)
    ControlHide($hGUI_tab, "", $StatusBar1)
    $StatusBar2 = _GUICtrlStatusBar_Create($hGUI_tab, $a_PartsRightEdge, $a_PartsText)
    ControlHide($hGUI_tab, "", $StatusBar1)
    _GUICtrlStatusBar_SetText($StatusBar0, "Part 0", 2)
    _GUICtrlStatusBar_SetText($StatusBar1, "Part 11", 2)
    _GUICtrlStatusBar_SetText($StatusBar2, "Part 222", 2)


    ; Run the GUI until the dialog is closed
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $cTab
                Switch GUICtrlRead($cTab)
                    Case 0
                        ControlShow($hGUI_tab, "", $StatusBar0)
                        ControlHide($hGUI_tab, "", $StatusBar1)
                        ControlHide($hGUI_tab, "", $StatusBar2)
                    Case 1
                        ControlHide($hGUI_tab, "", $StatusBar0)
                        ControlShow($hGUI_tab, "", $StatusBar1)
                        ControlHide($hGUI_tab, "", $StatusBar2)
                    Case 2
                        ControlHide($hGUI_tab, "", $StatusBar0)
                        ControlHide($hGUI_tab, "", $StatusBar1)
                        ControlShow($hGUI_tab, "", $StatusBar2)
                EndSwitch
        EndSwitch
    WEnd
EndFunc   ;==>Example

I hope that is a suitable solution. Please ask if you have any questions about the code. :)

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

 

Link to comment
Share on other sites

guwguw,

You cannot have a statusbar inside each tab - they are not GUIs. But you could have a child GUI just underneath the tab and show the statusbar associated with the selected tab like this: ;)

Thanks, Melba!

At least my ignorance (inability to find the proper context) was justified.

Ultimately, your solution looks quite acceptable - way better than a frozen status bar, lol.

Thanks for the help!

Link to comment
Share on other sites

Alternatively, use a function to set your status bar text. Pass in the tab number as one of the parameters of the function and store the text in a global array using the tab number as the index. Then when you switch tabs and call the function to show or hide UI elements, just set the statusbar text along with it.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...