Jump to content
TheWizEd

Add controls to Tab Item

Recommended Posts

TheWizEd

How to add controls to a tab item dynamically?  A tab has a set of common input controls but depending on a condition the controls following it vary.  For example, if a condition is set the following may be a combobox and radio buttons.  If the condition changes the combobox and radio go a way and are replaced with a checkbox and input control.  I don't see any handle or control passed to tab or tab item.

Edited by TheWizEd

Share this post


Link to post
Share on other sites
Bilgus

I'm not a big fan of the tab controls personally so there are probably other ways but this and the post just previous are one way to skin this cat

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
;#include <GuiTab.au3>
#include <StaticConstants.au3>
;#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>


$Form1 = GUICreate("Tabbed Notebook Dialog", 419, 311, 299, 218)

Global Enum $eC1_delete, $eC1_del_all, $eC1_update, $eC1_shift_dn, $eC1_shift_up, _
        $eC1_closepath, $eC1_showimg, $eC1_lock, $eC1_undo, $eC1_redo, $aCtl1_LAST
Global $g_ahCtl1[$aCtl1_LAST]

;-------------------------------------------------------------------------------
Global Enum $eC2_zin, $eC2_zout, $eC2_dgroup, $eC2_decx, $eC2_incx, $eC2_decy, _
        $eC2_incy, $eC2_edit_rot, $eC2_rot, $eC2_ud_rot, $eC2_rev, $eC2_toall, $aCtl2_LAST
Global $g_ahCtl2[$aCtl2_LAST]

Global Enum $eC3_open, $eC3_input1, $aCtl3_LAST
Global $g_ahCtl3[$aCtl3_LAST]

Global $g_hTab1 = GUICtrlCreateTab(8, 8, 396, 256)
;GUICtrlCreateLabel("", 8, 28, 396, 256, $SS_WHITERECT)
;GUICtrlSetState(-1, $GUI_DISABLE)

$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
$TabSheet1 = GUICtrlCreateTabItem("TabSheet2")
$TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
GUICtrlCreateTabItem("") ; end tabitem definition

Control_Create_TabGroup1(30, 35)
Control_Create_TabGroup2(30, 35)
Control_Create_TabGroup3(30, 35)
Tab1_Select()

GUISetState(@SW_SHOW)

Global $g_nMsg = 0
While 1
    $g_nMsg = GUIGetMsg()
    Switch $g_nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $g_hTab1
            Tab1_Select()
        Case $g_ahCtl3[$eC3_open]
            $FolderPath = "C:\Windows"
            ShellExecute($FolderPath, "", "", $SHEX_OPEN)
    EndSwitch
WEnd

Func Tab1_Select()
    Local $tabindex = GUICtrlRead($g_hTab1)
    Local Const $aStates[2] = [$GUI_HIDE, $GUI_SHOW]
    ;ConsoleWrite("tab" & $tabindex + 1 & "_selected" & @CRLF)

    For $i = 0 To UBound($g_ahCtl1) - 1
        GUICtrlSetState($g_ahCtl1[$i], $aStates[$tabindex = 0])
    Next
    For $i = 0 To UBound($g_ahCtl2) - 1
        GUICtrlSetState($g_ahCtl2[$i], $aStates[$tabindex = 1])
    Next
    For $i = 0 To UBound($g_ahCtl3) - 1
        GUICtrlSetState($g_ahCtl3[$i], $aStates[$tabindex = 2])
    Next
EndFunc   ;==>Tab1_Select

Func Control_Create_TabGroup1($iX, $iY)
    Static Local $IsInitialized = False
    If $IsInitialized Then Return
    $IsInitialized = True
    $g_ahCtl1[$eC1_delete] = GUICtrlCreateButton("Delete", $iX + 0, $iY + 0, 50, 20)
    $g_ahCtl1[$eC1_shift_dn] = GUICtrlCreateButton("+", $iX + 70, $iY + 0, 20, 20)
    $g_ahCtl1[$eC1_shift_up] = GUICtrlCreateButton("-", $iX + 95, $iY + 0, 20, 20)
    $g_ahCtl1[$eC1_del_all] = GUICtrlCreateButton("Delete All", $iX + 0, $iY + 25, 50, 20)
    $g_ahCtl1[$eC1_update] = GUICtrlCreateButton("Update", $iX + 70, $iY + 25, 50, 20)
    $g_ahCtl1[$eC1_undo] = GUICtrlCreateButton("Undo", $iX + 0, $iY + 50, 50, 20)
    $g_ahCtl1[$eC1_redo] = GUICtrlCreateButton("Redo", $iX + 70, $iY + 50, 50, 20)
    GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_DISABLE)
    GUICtrlSetState($g_ahCtl1[$eC1_redo], $GUI_DISABLE)

    $g_ahCtl1[$eC1_closepath] = GUICtrlCreateCheckbox("Complete", $iX + 0, $iY + 70, 65, 25)
    $g_ahCtl1[$eC1_showimg] = GUICtrlCreateCheckbox("Image", $iX + 0, $iY + 90, 65, 25)
    $g_ahCtl1[$eC1_lock] = GUICtrlCreateCheckbox("Locked", $iX + 0, $iY + 110, 65, 25)
EndFunc   ;==>Control_Create_TabGroup1

Func Control_Create_TabGroup2($iX, $iY)
    Static Local $IsInitialized = False
    If $IsInitialized Then Return
    $IsInitialized = True

    $g_ahCtl2[$eC2_rev] = GUICtrlCreateButton("Reverse", $iX + 0, $iY + 0, 50, 20)
    $g_ahCtl2[$eC2_edit_rot] = GUICtrlCreateInput("0", $iX + 0, $iY + 25, 40, 20)
    $g_ahCtl2[$eC2_ud_rot] = GUICtrlCreateUpdown(-1)
    GUICtrlSetLimit($eC2_ud_rot, 360, -360)
    $g_ahCtl2[$eC2_rot] = GUICtrlCreateButton("", $iX + 40, $iY + 25, 10, 20)

    $g_ahCtl2[$eC2_dgroup] = GUICtrlCreateGroup("Coords", 5 + $iX + 70, $iY + 0, 55, 70)
    $g_ahCtl2[$eC2_decy] = GUICtrlCreateButton("-", 24 + $iX + 70, 16 + $iY + 0, 17, 17)
    $g_ahCtl2[$eC2_incy] = GUICtrlCreateButton("+", 24 + $iX + 70, 48 + $iY + 0, 17, 17)
    $g_ahCtl2[$eC2_decx] = GUICtrlCreateButton("-", 8 + $iX + 70, 32 + $iY + 0, 17, 17)
    $g_ahCtl2[$eC2_incx] = GUICtrlCreateButton("+", 40 + $iX + 70, 32 + $iY + 0, 17, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)

    $g_ahCtl2[$eC2_zout] = GUICtrlCreateButton("Zoom -", $iX + 0, $iY + 75, 50, 20)
    $g_ahCtl2[$eC2_zin] = GUICtrlCreateButton("Zoom +", $iX + 75, $iY + 75, 50, 20)
    $g_ahCtl2[$eC2_toall] = GUICtrlCreateCheckbox("Apply to all", $iX + 0, $iY + 100, 80, 25)
EndFunc   ;==>Control_Create_TabGroup2

Func Control_Create_TabGroup3($iX, $iY)
    Static Local $IsInitialized = False
    If $IsInitialized Then Return
    $IsInitialized = True

    $g_ahCtl3[$eC3_open] = GUICtrlCreateButton("Open", $iX + 0, $iY + 0, 50, 20)
    $g_ahCtl3[$eC3_input1] = GUICtrlCreateInput("Input1", $iX + 0, $iY + 25, 40, 20)
EndFunc   ;==>Control_Create_TabGroup3

 

Edited by Bilgus

Share this post


Link to post
Share on other sites
Melba23

TheWizEd,

Use GUISwitch with the tabitemID parameter to tell AutoIt on which tab to create the controls.

M23


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
Bilgus

Melba is saying something like this

Expanded a bit from the helpfile example..

#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $IdButton0, $IdButton2
    Local $hGui = GUICreate("My GUI Tab", 250, 250); will create a dialog box that when displayed is centered

    GUISetBkColor(0x00E0FFFF)
    GUISetFont(9, 300)

    Local $idTab = GUICtrlCreateTab(10, 10, 200, 220)

    Local $IdTab0 = GUICtrlCreateTabItem("tab0")
    GUICtrlCreateLabel("label0", 30, 80, 50, 20)
    Local $IdOK0 = GUICtrlCreateButton("OK0", 20, 50, 50, 20)
    GUICtrlCreateInput("default", 80, 50, 70, 20)

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

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

    GUICtrlCreateTabItem(""); end tabitem definition

    GUICtrlCreateLabel("Click on tab and see the title", 20, 230, 250, 20)

    GUISetState(@SW_SHOW)

    Local $idMsg
    ; Loop until the user exits.
    While 1
        $idMsg = GUIGetMsg()
        Switch $idMsg

            Case $GUI_EVENT_CLOSE
                ExitLoop
        Case $idTab
            ; display the clicked tab
            WinSetTitle("My GUI Tab", "", "My GUI Tab" & GUICtrlRead($idTab))
            Case $IdOK0
                If Not $IdButton0 Then
                GUISwitch($hGui, $IdTab2)
                $IdButton0 = GUICtrlCreateButton("Added", 140, 130)
                GUICtrlCreateTabItem("")
                EndIF
            Case $IdOK1
                ConsoleWrite("DELETE")
                GUICtrlDelete($IdButton0)
                GUICtrlDelete($IdButton2)
                $IdButton0 = 0
                $IdButton2 = 0
            Case $IdOk2
                If Not $IdButton2 Then
                GUISwitch($hGui, $IdTab0)
                $IdButton2 = GUICtrlCreateButton("Added", 20, 100)
                GUICtrlCreateTabItem("")
                Endif
        EndSwitch
    WEnd
EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites
TheWizEd

Thanks to both of you.  After snooping through all the Functions I did discover GUISwitch which I think will solve my problem.

It seems AutoIt stores the value of the last window and control somewhere and that can be used to chain controls and data.

Edited by TheWizEd

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.