Navigate to the next tab on a GUI on button press? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
submeg
Posts: 328
Joined: 14 Apr 2017, 20:39
Contact:

Navigate to the next tab on a GUI on button press?

Post by submeg » 27 Jan 2024, 19:49

Hi all,

Have started to delve into v2 with GUIs. I have created a GUI with tabs:

Code: Select all

#Requires AutoHotkey v2+
#SingleInstance Force

SSGui := Gui()
Tab := SSGui.Add("Tab3","vTabSelect h470 w480", ["System","Symptoms","Tab3","Tab4","Tab5","Tab6","Tab7","Tab8"])

Tab.UseTab(1)
Btn := SSGui.Add("Button", "default x380 y440 w100", "Next")
Btn.OnEvent("Click", SymptomTab)

SymptomTab(*)
{

	Tab.Choose("Symptoms")	;Works

	;Tab.Choose(Next) 		;Wrong
	;Tab.ChooseNext			;Wrong

}

SSGui.Show("W500 H510")
Is there any way to just jump to the next tab?

Also, is:

Code: Select all

vTabSelect
correct here? Can it have any use / is my syntax incorrect?
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

User avatar
mikeyww
Posts: 27241
Joined: 09 Sep 2014, 18:38

Re: Navigate to the next tab on a GUI on button press?

Post by mikeyww » 27 Jan 2024, 23:02

Press Ctrl+Tab.

The question about your variable is what you would like to achieve by using it. Tab usage

User avatar
submeg
Posts: 328
Joined: 14 Apr 2017, 20:39
Contact:

Re: Navigate to the next tab on a GUI on button press?

Post by submeg » 28 Jan 2024, 00:48

mikeyww wrote:
27 Jan 2024, 23:02
Press Ctrl+Tab.
Is there a method / event that is built into ListBoxes that I can use? I guess I can just do SendInput as a back up.

I have found that splitting out moving to each tab into separate functions is useful, as I can perform different actions when switching between tabs.
what you would like to achieve by using it
Unsure at this point, the problem I was trying to solve became obvious as I started typing this post, but maybe it will have a use later...

Code: Select all


Tab := SSGui.Add("Tab3",...

I realised I could navigate to a different tab using:

Code: Select all


Tab.Choose("Name of tab")

Oops!
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

User avatar
Datapoint
Posts: 303
Joined: 18 Mar 2018, 17:06

Re: Navigate to the next tab on a GUI on button press?  Topic is solved

Post by Datapoint » 28 Jan 2024, 03:28

submeg wrote:
28 Jan 2024, 00:48
I have found that splitting out moving to each tab into separate functions is useful, as I can perform different actions when switching between tabs.
Not sure if this is what you are going for. If you want a specific function to run when switching tabs, you could detect when a tab is changed and then do certain actions based on what tab was activated and/or deactivated. You wouldn't need a button on every tab and separate functions to switch tabs, but instead use if-statements based on what tab it is.

Code: Select all

#Requires AutoHotkey v2+
#SingleInstance Force

SSGui := Gui()
Tab := SSGui.Add("Tab3","vTabSelect h470 w480",
	tabList := ["System","Symptoms","Tab3","Tab4","Tab5","Tab6","Tab7","Tab8"])
Tab.OnEvent("Change", TabChanged)

SSGui.Show("W500 H510")

TabChanged(GuiCtrlObj, Info) {
	static PrevTab := 1
	NewTab := GuiCtrlObj.Value
	MsgBox "Switched from tab " PrevTab " (" tabList[PrevTab] ") to " NewTab " (" tabList[NewTab] ")"
	PrevTab := NewTab
}
If you want to have a next button, here is one idea:

Code: Select all

#Requires AutoHotkey v2+
#SingleInstance Force

SSGui := Gui()
Tab := SSGui.Add("Tab3","vTabSelect h470 w480",
	tabList := ["System","Symptoms","Tab3","Tab4","Tab5","Tab6","Tab7","Tab8"])

for i, tabName in tabList {
	Tab.UseTab(i)
	SSGui.Add("Button", "default x380 y440 w100", "Next").OnEvent("Click", NextTab)
}

SSGui.Show("W500 H510")

NextTab(GuiCtrlObj, Info) {
	thisTab := Tab.Value
	nextTab := (thisTab = tabList.Length) ? 1 : ++thisTab
	Tab.Choose(nextTab)
}

User avatar
submeg
Posts: 328
Joined: 14 Apr 2017, 20:39
Contact:

Re: Navigate to the next tab on a GUI on button press?

Post by submeg » 02 Feb 2024, 07:15

Datapoint wrote:
28 Jan 2024, 03:28

Not sure if this is what you are going for. If you want a specific function to run when switching tabs, you could detect when a tab is changed and then do certain actions based on what tab was activated and/or deactivated. You wouldn't need a button on every tab and separate functions to switch tabs, but instead use if-statements based on what tab it is.

...

If you want to have a next button, here is one idea:
@Datapoint, These are both great examples, thank you so much! I think I will end up using both at some point.

Such obvious answers when you see them written out so succinctly; your scripts are much appreciated!
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

User avatar
Seven0528
Posts: 398
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: Navigate to the next tab on a GUI on button press?

Post by Seven0528 » 02 Feb 2024, 12:18

 It's also acceptable to pass the Tab itself instead of Tab.hWnd.

Code: Select all

SymptomTab(*) ;  A. This method is newly introduced in v2.
{
    currIndex:=ControlGetIndex(Tab.hWnd)
    newIndex:=currIndex+1
    ControlChooseIndex(newIndex, Tab.hWnd)
}

Code: Select all

SymptomTab(*) ;  B. This method was predominantly used in v1.
{
    static TCM_SETCURFOCUS:=0x1330
            ,TCM_SETCURSEL:=0x130C
    currIndex:=ControlGetIndex(Tab.hWnd)
    newIndex:=currIndex+1
    SendMessage(TCM_SETCURFOCUS, -1+newIndex,, Tab.hWnd), Sleep(0)
    SendMessage(TCM_SETCURSEL, -1+newIndex,, Tab.hWnd)
}
 To discover how many tabs (pages) exist in a tab control, follow this example:

Code: Select all

tabCount:=SendMessage(TCM_GETITEMCOUNT:=0x1304,,, Tab.hWnd)
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.

Post Reply

Return to “Ask for Help (v2)”