Jump to content

GUISwitch not moving control back to main window


square65
 Share

Recommended Posts

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.

#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 by square65
Link to comment
Share on other sites

  • Moderators

square65,

Do not use GUISwitch until after the GUI has been displayed. Before that just add the controls inside the tabitem creation structure: ;)

#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   ;==>terminate
All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

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 by square65
Link to comment
Share on other sites

  • Moderators

square65,

My pleasure. You might find the Tabs tutorial in the Wiki worth a look. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

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