Jump to content

Problems with tabs ( GUICtrlCreateTab )


Allow2010
 Share

Recommended Posts

Hi,

i created a gui that uses tabs (GUICtrlCreateTab).

I use inputs in the tabs (for example Tab1 has input1 and tab2 has input2 )

When i start the gui and type something in input1 on tab1 and then switch to tab2, the input on tab1 still has the focus (until i click input2 on tab2).

This results in the problem, that when i type without first clicking on input2 the text is typed into input1 (but this happends hidden, i can not see it until i switch back to tab1).

Is there a way to set the focus/active gui element when i change the tab?

Thanks in advance for your ideas:-)

cu

allow

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TabConstants.au3>
$hGUI = GUICreate("TestGUI", 300, 300)
$hTab = GUICtrlCreateTab(10, 10, 280, 280)
$tab1 = GUICtrlCreateTabItem("tab1")
GUICtrlCreateLabel("input1", 20, 50, 150, 20)
$input1 = GUICtrlCreateInput("", 20, 70, 250, 20)
$tab2 = GUICtrlCreateTabItem("tab2")
GUICtrlCreateLabel("input2", 20, 50, 150, 20)
$input2 = GUICtrlCreateInput("", 20, 70, 250, 20)
GUICtrlCreateTabItem("")
GUISetState()
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

here it is.

when you run the code do the following:

1. click into input1 in tab1

2. enter letters (aaaaaa)

3. click on tab2

(do not click into the input2 control, just type)

4. enter letters (bbbbbb)

5. click on tab1

the letters you typed in step 2 are now replaced by the lettery you typed in step 4 because the focus was still on the input1 control on tab1 even when i am on tab2.

In my gui this often leads to the problem that a users changes values by mistake without noticing because those changes happen on a tab that is not visible

Is there a way to know when a tab is clicked and then activate the first control on that tab?

Edited by Allow2010
Link to comment
Share on other sites

$msg = GUIGetMsg()
Switch $msg
    Case $GUI_EVENT_CLOSE
        ExitLoop
    Case $tab           
        Switch GUICtrlRead($tab)
            Case 1
                 ControlFocus($hWnd, "", "Edit2")
            Case 1
                 ControlFocus($hWnd, "", "Edit1")
        EndSwitch

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <TabConstants.au3>

$hGUI = GUICreate("TestGUI", 300, 300)

$hTab = GUICtrlCreateTab(10, 10, 280, 280)

$tab1 = GUICtrlCreateTabItem("tab1")

GUICtrlCreateLabel("input1", 20, 50, 150, 20)

$input1 = GUICtrlCreateInput("", 20, 70, 250, 20)

$tab2 = GUICtrlCreateTabItem("tab2")

GUICtrlCreateLabel("input2", 20, 50, 150, 20)

$input2 = GUICtrlCreateInput("", 20, 70, 250, 20)

GUICtrlCreateTabItem("")

GUISetState()

While 1

$iMsg = GUIGetMsg()

Switch $iMsg

Case $GUI_EVENT_CLOSE

Exit

Case $hTab

Switch GUICtrlRead($hTab)

Case 0

GUICtrlSetState($input1, $GUI_FOCUS)

Case 1

GUICtrlSetState($input2, $GUI_FOCUS)

EndSwitch

EndSwitch

WEnd

Well the code from AZJIO brought me in the right directoion, so "Thank YOU" !

But his code is not correct (Case 1 /Case 1). Also i think the use of ControLFocus is not optimal here...

Link to comment
Share on other sites

  • Moderators

Allow2010,

Also i think the use of ControLFocus is not optimal here...

You have to change the focus yourself - Windows does not as I showed here, although I used another strategy to change the keyboard focus. :)

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