AlexIsProgramming Posted May 28, 2021 Share Posted May 28, 2021 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? expandcollapse popup#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 comment Share on other sites More sharing options...
Subz Posted May 29, 2021 Share Posted May 29, 2021 Remove the 2 x "GUICtrlCreateTabItem("")" within the Case $addButtonToTab1 Link to comment Share on other sites More sharing options...
AlexIsProgramming Posted May 29, 2021 Author Share Posted May 29, 2021 6 hours ago, Subz said: Remove the 2 x "GUICtrlCreateTabItem("")" within the Case $addButtonToTab1 But than I still have to change between the taps to see the new button. I would like to add and display the new button directly. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 29, 2021 Moderators Share Posted May 29, 2021 AlexisProgramming, How about this: expandcollapse popup#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 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...
AlexIsProgramming Posted May 29, 2021 Author Share Posted May 29, 2021 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) expandcollapse popup#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 comment Share on other sites More sharing options...
Moderators Melba23 Posted May 29, 2021 Moderators Share Posted May 29, 2021 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 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