Jump to content

Adding Controls to a Dynamically Created Tab [Solved]


Recommended Posts

I'm trying to create a tab dynamically.  Could I also add controls to to a tab item after the fact?  Here is what I have so far demonstrating the problem which you'll see when ran.

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

Global $hWnd = GUICreate("Tab Experiment", 400, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

Global $button_array[3] = [GUICtrlCreateButton("Click To Create A Tab Control.", 20, 20)]

Global $hTab

GUISetState(@SW_SHOWNORMAL)

Do
    Switch GUIGetMsg()
        Case $button_array[0]
            GUICtrlSetState($button_array[0], $GUI_HIDE)
        
            $hTab = _GUICtrlTab_Create($hWnd, 10, 10, 380, 280)

            _GUICtrlTab_InsertItem($hTab, 0, "Tab 1")    
            
            $button_array[1] = GUICtrlCreateButton("Tab 1 Button", 30, 30)
            
            _GUICtrlTab_InsertItem($hTab, 1, "Tab 2")
            
            $button_array[2] = GUICtrlCreateButton("Tab 2 Button", 60, 60)
            
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
Until False

 

Edited by jaberwacky
Link to comment
Share on other sites

Nevermind.  Helpfile says in GUISwitch: "Using the tabitemID allow to create new control in the specified tabitem control. Don't forget to close tabitem definition GUICtrlCreateTabItem("")
"

Link to comment
Share on other sites

Sweet!  Here is the working code.

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

Global $hWnd = GUICreate("Tab Experiment", 400, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

Global $button_array[3] = [GUICtrlCreateButton("Click To Create A Tab Control.", 20, 20)]

Global $hTab

GUISetState(@SW_SHOWNORMAL)

Do
    Switch GUIGetMsg()
        Case $button_array[0]
            GUICtrlSetState($button_array[0], $GUI_HIDE)
            
            $hTab = GUICtrlCreateTab(10, 10, 380, 280)

            Global $idTabItem1 = GUICtrlCreateTabItem("Tab 1")
            
            Global $idTabItem2 = GUICtrlCreateTabItem("Tab 2")
            
            GUICtrlCreateTabItem('')
            
            GUISwitch($hWnd, $idTabItem1)
            
            $button_array[1] = GUICtrlCreateButton("Tab 1 Button", 20, 40)
            
            GUICtrlCreateTabItem('')
            
            GUISwitch($hWnd, $idTabItem2)
            
            $button_array[2] = GUICtrlCreateButton("Tab 2 Button", 90, 40)
            
            GUICtrlCreateTabItem('')
            
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
Until False

 

Edited by jaberwacky
Link to comment
Share on other sites

  • 4 years later...

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...