Jump to content

How to dynamically add controls Into a control?[SOLVED]


Recommended Posts

#include <GUIConstantsEx.au3>

Example()

Func Example()
    GUICreate("My GUI Tab")

    GUISetBkColor(0x00E0FFFF)
    GUISetFont(9, 300)

    GUICtrlCreateTab(10, 10, 380, 256)

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

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

    GUICtrlCreateTabItem("tab----2")
    GUICtrlSetState(-1, $GUI_SHOW)
    GUICtrlCreateLabel("label2", 30, 80, 50, 20)
    GUICtrlCreateButton("OK2", 140, 50, 50)

    GUICtrlCreateTabItem("")

   Local $idButtonAdd= GUICtrlCreateButton("Add", 20, 296, 75,35)

    GUISetState(@SW_SHOW)

    Local $idMsg

    While 1
        $idMsg = GUIGetMsg()
        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
        If $idMsg = $idButtonAdd Then
            Local $idDate_Tab2 = GUICtrlCreateMonthCal("2048/03/25", 20,175,160,35);want to create a MonthCal Control within TabItem 'tab----2'
            Local $idLabl_Tab1 = GUICtrlCreateEdit("Test", 35,120,240,30);want to create a Label Control within TabItem 'tab----1'
            Local $idLabl_Tab0 = GUICtrlCreateIcon("shell32.dll", 310,285, 225);want to create an Icon Control within TabItem 'tab----0'
        EndIf
    WEnd
EndFunc

As shown above, if want to dynamically add controls to the Tab-control's tabitem, how locate it separately? Thanks in advance!

Edited by Letraindusoir
Link to comment
Share on other sites

Use GUISwitch($hGui, $hTab0) to select a tab which will get the items, then

add as many items to the tab, as needed, then

use the GUICtrlCreateTabItem("") to stop adding items. 

 

#include <GUIConstantsEx.au3>

Example()

Func Example()
    Global $hTab, $hTabActive

    $hGui = GUICreate("My GUI Tab")

    GUISetBkColor(0x00E0FFFF)
    GUISetFont(9, 300)

    $hTab = GUICtrlCreateTab(10, 10, 380, 256)

    $hTab0 = GUICtrlCreateTabItem("tab----0")
    GUICtrlCreateLabel("label0", 30, 80, 50, 20)
    GUICtrlCreateButton("OK0", 20, 50, 50, 20)
    GUICtrlCreateInput("default", 80, 50, 70, 20)

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

    $hTab2 = GUICtrlCreateTabItem("tab----2")
    GUICtrlSetState(-1, $GUI_SHOW)
    GUICtrlCreateLabel("label2", 30, 80, 50, 20)
    GUICtrlCreateButton("OK2", 140, 50, 50)

    GUICtrlCreateTabItem("")

    Local $idButtonAdd = GUICtrlCreateButton("Add", 20, 296, 75, 35)

    GUISetState(@SW_SHOW)
    
    Local $idMsg

    While 1
        $idMsg = GUIGetMsg()
        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
        If $idMsg = $idButtonAdd Then
            ;$hTabActive = GUICtrlRead($hTab)
            GUISwitch($hGui, $hTab2)
            Local $idDate_Tab2 = GUICtrlCreateMonthCal("2048/03/25", 20, 175, 160, 35, -1, -1) ;want to create a MonthCal Control within TabItem 'tab----2'
            GUICtrlCreateTabItem("")
            
            GUISwitch($hGui, $hTab1)
            Local $idLabl_Tab1 = GUICtrlCreateEdit("Test", 35, 120, 240, 30) ;want to create a Label Control within TabItem 'tab----1'
            GUICtrlCreateTabItem("")
            
            GUISwitch($hGui, $hTab0)
            Local $idLabl_Tab0 = GUICtrlCreateIcon("shell32.dll", 310, 285, 225) ;want to create an Icon Control within TabItem 'tab----0'
            GUICtrlCreateTabItem("")
        EndIf

    WEnd
EndFunc   ;==>Example

 

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

1 hour ago, Dan_555 said:

Use GUISwitch($hGui, $hTab0) to select a tab which will get the items, then

add as many items to the tab, as needed, then

use the GUICtrlCreateTabItem("") to stop adding items. 

 

#include <GUIConstantsEx.au3>

Example()

Func Example()
    Global $hTab, $hTabActive

    $hGui = GUICreate("My GUI Tab")

    GUISetBkColor(0x00E0FFFF)
    GUISetFont(9, 300)

    $hTab = GUICtrlCreateTab(10, 10, 380, 256)

    $hTab0 = GUICtrlCreateTabItem("tab----0")
    GUICtrlCreateLabel("label0", 30, 80, 50, 20)
    GUICtrlCreateButton("OK0", 20, 50, 50, 20)
    GUICtrlCreateInput("default", 80, 50, 70, 20)

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

    $hTab2 = GUICtrlCreateTabItem("tab----2")
    GUICtrlSetState(-1, $GUI_SHOW)
    GUICtrlCreateLabel("label2", 30, 80, 50, 20)
    GUICtrlCreateButton("OK2", 140, 50, 50)

    GUICtrlCreateTabItem("")

    Local $idButtonAdd = GUICtrlCreateButton("Add", 20, 296, 75, 35)

    GUISetState(@SW_SHOW)
    
    Local $idMsg

    While 1
        $idMsg = GUIGetMsg()
        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
        If $idMsg = $idButtonAdd Then
            ;$hTabActive = GUICtrlRead($hTab)
            GUISwitch($hGui, $hTab2)
            Local $idDate_Tab2 = GUICtrlCreateMonthCal("2048/03/25", 20, 175, 160, 35, -1, -1) ;want to create a MonthCal Control within TabItem 'tab----2'
            GUICtrlCreateTabItem("")
            
            GUISwitch($hGui, $hTab1)
            Local $idLabl_Tab1 = GUICtrlCreateEdit("Test", 35, 120, 240, 30) ;want to create a Label Control within TabItem 'tab----1'
            GUICtrlCreateTabItem("")
            
            GUISwitch($hGui, $hTab0)
            Local $idLabl_Tab0 = GUICtrlCreateIcon("shell32.dll", 310, 285, 225) ;want to create an Icon Control within TabItem 'tab----0'
            GUICtrlCreateTabItem("")
        EndIf

    WEnd
EndFunc   ;==>Example

 

Very much appreciated. it Works good,thanks  for your help!

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