Jump to content

How to add a control to a TabItem after its has been created and directly make it visible


Recommended Posts

Hey to all,

I would like to add a control to a TabItem later in the game and make it directly visible. But so far I'm obviously missing something...

In my example down below you will create no Button in tab 0 and a Button within tab 1 and tab 2 each time you press the "Create New" Button. Afterwards you stay on the previously selected tab. My script is indeed creating a button in tab 1 and 2 and will stay on the selected tab but will show everytime the last added button on the current selected tab. Only after switching between the TabItems everything will be shown correctly. What am I missing? Can somebody please help me with this one?

 

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>

Global $aTab[3]
Global $_counter = 50

$hGUI = GUICreate("Add Ctrl to existing Tab", 300, 200)

$Tab = GUICtrlCreateTab(20, 10, 260, 150)

$aTab[0] = GUICtrlCreateTabItem("Tab 0")
$aTab[1] = GUICtrlCreateTabItem("Tab 1")
$aTab[2] = GUICtrlCreateTabItem("Tab 2")
GUICtrlCreateTabItem("")

$addButtonToTab1 = GUICtrlCreateButton("Create New", 20, 170, 80, 20)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
         Case $addButtonToTab1
            Local $_CurFocus = _GUICtrlTab_GetCurFocus ( $Tab )
            ConsoleWrite(_GUICtrlTab_GetCurFocus ( $Tab ))
            GUISwitch($hGUI, $aTab[1])
            GUICtrlCreateButton("Test1", $_counter, 50)
            GUICtrlCreateTabItem("")

            GUISwitch($hGUI, $aTab[2])
            GUICtrlCreateButton("Test2", $_counter, 50)
            $_counter += 50
            GUICtrlCreateTabItem("")

            _GUICtrlTab_SetCurSel($tab, $_CurFocus)
    EndSwitch
WEnd

 

Link to post
Share on other sites
  • Moderators

AlexisProgramming,

How about this:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>

Global $aTab[3]
Global $_counter = 50

$hGUI = GUICreate("Add Ctrl to existing Tab", 300, 200)

$Tab = GUICtrlCreateTab(20, 10, 260, 150)

$aTab[0] = GUICtrlCreateTabItem("Tab 0")
$aTab[1] = GUICtrlCreateTabItem("Tab 1")
$aTab[2] = GUICtrlCreateTabItem("Tab 2")
GUICtrlCreateTabItem("")

$addButtonToTab1 = GUICtrlCreateButton("Create New", 20, 170, 80, 20)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $addButtonToTab1
            $_CurFocus = GUICtrlRead($Tab)
            
            GUISwitch($hGUI, $aTab[1])
            GUICtrlCreateButton("Test1", $_counter, 50)
            GUICtrlCreateTabItem("")
            _GUICtrlTab_SetCurSel($Tab, 1)
            GUICtrlSetState($aTab[1], $GUI_SHOW)

            GUISwitch($hGUI, $aTab[2])
            GUICtrlCreateButton("Test2", $_counter, 50)
            $_counter += 50
            GUICtrlCreateTabItem("")
            _GUICtrlTab_SetCurSel($Tab, 2)
            GUICtrlSetState($aTab[2], $GUI_SHOW)

            GUISwitch($hGUI)

            GUICtrlSetState($aTab[$_CurFocus], $GUI_SHOW)

    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

 

Link to post
Share on other sites

Perfect! That's exactly what I want. Thank you. I guess the main point is to GUISwitch to the main GUI after adding the Buttons.

 

Just for my understanding, couldn't I remove Part 1 and Part 2 in my code to clean it up?

 

;Part 1
GUICtrlCreateTabItem("")
_GUICtrlTab_SetCurSel($Tab, 1)
GUICtrlSetState($aTab[1], $GUI_SHOW)

;Part 2
_GUICtrlTab_SetCurSel($Tab, 2)
GUICtrlSetState($aTab[2], $GUI_SHOW)

 

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>

Global $aTab[3]
Global $_counter = 50

$hGUI = GUICreate("Add Ctrl to existing Tab", 300, 200)

$Tab = GUICtrlCreateTab(20, 10, 260, 150)

$aTab[0] = GUICtrlCreateTabItem("Tab 0")
$aTab[1] = GUICtrlCreateTabItem("Tab 1")
$aTab[2] = GUICtrlCreateTabItem("Tab 2")
GUICtrlCreateTabItem("")

$addButtonToTab1 = GUICtrlCreateButton("Create New", 20, 170, 80, 20)

GUISetState()


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $addButtonToTab1
            $_CurFocus = GUICtrlRead($Tab)

            GUISwitch($hGUI, $aTab[1])
            GUICtrlCreateButton("Test1", $_counter, 50)
;Part 1

            GUISwitch($hGUI, $aTab[2])
            GUICtrlCreateButton("Test2", $_counter, 50)
            $_counter += 50
            GUICtrlCreateTabItem("") ;stop adding future ctrl into tabitem 
;Part 2

            GUISwitch($hGUI)

            GUICtrlSetState($aTab[$_CurFocus], $GUI_SHOW)

    EndSwitch
WEnd

 

Link to post
Share on other sites
  • Moderators

AlexisProgramming,

I would leave in the first GUICtrlCreateTabItem("") - as far as I know it should be used on each tab once control creation is terminated:

Case $addButtonToTab1
    $_CurFocus = GUICtrlRead($Tab)

    GUISwitch($hGUI, $aTab[1])
    GUICtrlCreateButton("Test1", $_counter, 50)
    GUICtrlCreateTabItem("")

    GUISwitch($hGUI, $aTab[2])
    GUICtrlCreateButton("Test2", $_counter, 50)
    $_counter += 50
    GUICtrlCreateTabItem("")

    GUISwitch($hGUI)

    GUICtrlSetState($aTab[$_CurFocus], $GUI_SHOW)

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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...