square65 Posted February 15, 2015 Share Posted February 15, 2015 (edited) I understand that if I replace GUISwitch($mainGUI) with GUICtrlCreateTabItem("") then it will do what I want (move our control back to the main tab so I can add UI elements there instead of within tabs) But I don't understand why GUISwitch isn't doing the same thing. expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ;enable GUI events Opt("GUIOnEventMode", 1) ;create and size main GUI window $mainGUI = GUICreate("AutoChess", 600, 800) ;specify a function to be called in the event the GUI is closed (x button) GUISetOnEvent($GUI_EVENT_CLOSE, "terminate") ;create a Close button that calls the same function as when the x button is hit Local $closeButton = GUICtrlCreateButton("Close", 520, 760, 60, 30) ;set the event for when the close button control is pressed GUICtrlSetOnEvent($closeButton, "terminate") ;create a tab GUICtrlCreateTab(40, 25, 520, 600) Local $operationTab = GUICtrlCreateTabItem("Operation") Local $setupTab = GUICtrlCreateTabItem("Setup") Local $toolsTab = GUICtrlCreateTabItem("Tools") ;put stuff in tabs GUISwitch($mainGUI, $operationTab) GUICtrlCreateButton("OK", 50, 50, 50) GUISwitch($mainGUI, $setupTab) GUICtrlCreateButton("OK2", 50, 50, 50) GUISwitch($mainGUI, $toolsTab) GUICtrlCreateButton("OK3", 50, 50, 50) ;this command moves current control back to main window, so additional ui elements don't automatically ;affect the 3rd tab which is the last control we interacted with ;GUICtrlCreateTabItem("") GUISwitch($mainGUI) GUICtrlCreateButton("test", 5, 5, 5) ;GUICtrlCreateTabItem("") ;display the GUI GUISetState() ;main program loop While 1 sleep(100) WEnd ;program termination function Func terminate() ; Note: At this point @GUI_CtrlId would equal $GUI_EVENT_CLOSE, ; and @GUI_WinHandle would equal $hMainGUI $closeConfirmationResponse = MsgBox(1, "Close Confirmation", "Sure you want to close?") if $closeConfirmationResponse = 1 Then Exit endif EndFunc local test Edited February 15, 2015 by square65 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 15, 2015 Moderators Share Posted February 15, 2015 square65,Do not use GUISwitch until after the GUI has been displayed. Before that just add the controls inside the tabitem creation structure: expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ;enable GUI events Opt("GUIOnEventMode", 1) ;create and size main GUI window $mainGUI = GUICreate("AutoChess", 600, 800) ;specify a function to be called in the event the GUI is closed (x button) GUISetOnEvent($GUI_EVENT_CLOSE, "terminate") ;create a Close button that calls the same function as when the x button is hit Local $closeButton = GUICtrlCreateButton("Close", 520, 760, 60, 30) ;set the event for when the close button control is pressed GUICtrlSetOnEvent($closeButton, "terminate") ;create a tab GUICtrlCreateTab(40, 25, 520, 600) ; Create tabitems... <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $operationTab = GUICtrlCreateTabItem("Operation") ; ...and then the controls to be placed on the tabitem... GUICtrlCreateButton("OK", 50, 50, 50) ; ...before creating the next tabitem Local $setupTab = GUICtrlCreateTabItem("Setup") GUICtrlCreateButton("OK2", 50, 50, 50) Local $toolsTab = GUICtrlCreateTabItem("Tools") GUICtrlCreateButton("OK3", 50, 50, 50) GUICtrlCreateTabItem("") ; and make sure to close the tab structure GUICtrlCreateButton("test", 5, 5, 40, 20) ;display the GUI GUISetState() ; Now if we want to add a control to a tab item we use GUISwitch - here we add a button to "Setup" <<<<<<<<<<<<<<<<<<< GUISwitch($mainGUI, $setupTab) GUICtrlCreateButton("Add button2", 100, 100, 100, 30) GUICtrlCreateTabItem("") ; again make sure to close the tab structure ; And return to the main GUI to create a new button there <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUISwitch($mainGUI) GUICtrlCreateButton("Add button main", 10, 760, 100, 30) ;main program loop While 1 Sleep(100) WEnd ;program termination function Func terminate() ; Note: At this point @GUI_CtrlId would equal $GUI_EVENT_CLOSE, ; and @GUI_WinHandle would equal $hMainGUI $closeConfirmationResponse = MsgBox(1, "Close Confirmation", "Sure you want to close?") If $closeConfirmationResponse = 1 Then Exit EndIf EndFunc ;==>terminateAll clear? 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...
square65 Posted February 15, 2015 Author Share Posted February 15, 2015 (edited) Yes I think so. In addition to the practice of creating elements inside the tabs at the time of creation of the tab, GUICtrlCreateTabItem("") is necessary to close the tab structure before we can jump around willy nilly again. Thanks for your great help again. Also, how are you able to create code segments in your post such that keywords link to documentation? Nevermind I see it's "[autoit]" - little weird that it's not one of the buttons in the post editor. Is this forum software not able to easily customize the UI for the post editor? Edited February 15, 2015 by square65 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 15, 2015 Moderators Share Posted February 15, 2015 square65,My pleasure. You might find the Tabs tutorial in the Wiki worth a look. 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