Sign in to follow this  
Followers 0
pollardd

Change the current tab

5 posts in this topic

Hi There,

I'm trying to change the current tab in a tab control programatically.

I have come up with a simple example of what I'm trying to do but can't get it to work.

Either _GUICtrlTabSetCurFocus isn't the right command to use or I'm no using it right.

Any ideas?

David

CODE
#include <GUIConstants.au3>

#include <GuiTab.au3>

GUICreate("Tab Set Current Focus", 300, 200) ; will create a dialog box that when displayed is centered

$tab = GUICtrlCreateTab(10, 10, 200, 100, $TCS_MULTILINE)

$tab0 = GUICtrlCreateTabItem("Tab-Zero")

$buttonzero = GUICtrlCreateButton("Goto Tab One", 200, 130, 90, 30)

GUICtrlCreateTabItem("") ; end tabitem definition

$tab1 = GUICtrlCreateTabItem("Tab-One")

$buttonone = GUICtrlCreateButton("Goto Tab Two", 200, 130, 90, 30)

GUICtrlCreateTabItem("") ; end tabitem definition

$tab2 = GUICtrlCreateTabItem("Tab-Two")

$buttontwo = GUICtrlCreateButton("Goto Tab Zero", 200, 130, 90, 30)

GUICtrlCreateTabItem("") ; end tabitem definition

GUISetState()

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $buttonzero

_GUICtrlTabSetCurFocus($tab,$tab1)

Case $msg = $buttonone

_GUICtrlTabSetCurFocus($tab,$tab2)

Case $msg = $buttontwo

_GUICtrlTabSetCurFocus($tab,$tab0)

EndSelect

WEnd

Share this post


Link to post
Share on other sites

Look at ControlCommand() & "CurrentTab", "TabLeft", "TabRight" commands.

Also Auto3Lib has functions for Tab control, for example:

_Tab_SetCurFocus($hWnd, $iIndex)

_Tab_SetCurSel($hWnd, $iIndex)

I think your problem is that you are using

_GUICtrlTabSetCurFocus() instead of _GUICtrlTabSetCurSel()

Share this post


Link to post
Share on other sites

Thanks :shocked: that solved part of the problem.

Now when I click on the tabs I see the different buttons but if I click on the button the tab changes but the previous button remains.

Any ideas how come I don't see the correct buttons when the tabs change?

David

#include <GUIConstants.au3>
#include <GuiTab.au3>

GUICreate("Tab Set Current Focus", 300, 200)  ; will create a dialog box that when displayed is centered

$tab = GUICtrlCreateTab(10, 10, 285, 180, $TCS_MULTILINE)

$tab0 = GUICtrlCreateTabItem("Tab-Zero")
$buttonzero = GUICtrlCreateButton("Goto Tab One", 200, 130, 90, 30)
GUICtrlCreateTabItem("") ; end tabitem definition

$tab1 = GUICtrlCreateTabItem("Tab-One")
$buttonone = GUICtrlCreateButton("Goto Tab Two", 200, 130, 90, 30)
GUICtrlCreateTabItem("") ; end tabitem definition

$tab2 = GUICtrlCreateTabItem("Tab-Two")
$buttontwo = GUICtrlCreateButton("Goto Tab Zero", 200, 130, 90, 30)
GUICtrlCreateTabItem("") ; end tabitem definition

GUISetState()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $buttonzero
            _GUICtrlTabSetCurSel($tab,1)
        Case $msg = $buttonone
            _GUICtrlTabSetCurSel($tab,2)
        Case $msg = $buttontwo
            _GUICtrlTabSetCurSel($tab,0)
    EndSelect
WEnd

Share this post


Link to post
Share on other sites

First: You don't need those lines like GUICtrlCreateTabItem("") after each tab, that's only meant for when you're completely done with the tabs (ie: you'd create a tab, put some controls in it, then create another tab, put more controls, then use that code to close the entire tab control, then put some more controls on the main GUI).

Second: It looks like the _GUICtrlTabSetCurSel only changes the tab control visually, it doesn't refresh the actual control.. the remarks for the function note this:

A tab control does not send a $TCN_SELCHANGING or $TCN_SELCHANGE

notification message when a tab is selected using this message.

Personally, I've always used GUICtrlSetState to set my tabs. Give this a try:

#include <GUIConstants.au3>

GUICreate("Tab Set Current Focus", 300, 200)  ; will create a dialog box that when displayed is centered

$tab = GUICtrlCreateTab(10, 10, 285, 180, $TCS_MULTILINE)

$tab0 = GUICtrlCreateTabItem("Tab-Zero")
$buttonzero = GUICtrlCreateButton("Goto Tab One", 200, 130, 90, 30)

$tab1 = GUICtrlCreateTabItem("Tab-One")
$buttonone = GUICtrlCreateButton("Goto Tab Two", 200, 130, 90, 30)

$tab2 = GUICtrlCreateTabItem("Tab-Two")
$buttontwo = GUICtrlCreateButton("Goto Tab Zero", 200, 130, 90, 30)
GUICtrlCreateTabItem("") ; end tabitem definition

GUISetState()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $buttonzero
            GUICtrlSetState($tab1, $GUI_SHOW)
        Case $msg = $buttonone
            GUICtrlSetState($tab2, $GUI_SHOW)
        Case $msg = $buttontwo
            GUICtrlSetState($tab0, $GUI_SHOW)
    EndSelect
WEnd

Share this post


Link to post
Share on other sites

Sorry it took me so long to get back but I just though I'd let other people who may be reading this.

IT WORKED :shocked:

The last suggestion did the trick.

David

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
Sign in to follow this  
Followers 0