Avatar of ross13
ross13
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Move focus to another tab

Hi,

I am currently creating a screen with multiple tabs in vb.net and i would lime to be able to move the user to set the focus to different tabs so the user does not need to click on them.
Any help is appreciated.

Regards,

Rosd
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
ross13

8/22/2022 - Mon
Giuseppe Pizzuto

what method will the user "use" ? Using TAB button, some function/key (F1..F12), some combination on keys... ???
rowansmith

The following programatically selects select the TabPage called "tabPage2" which is one of the Tab in the TabControl tabControl1 and displays it in the tabControl.

tabControl1.SelectedIndex = tabControl1.TabPages.IndexOf(tabControl1.TabPages["tabPage2"]);

Open in new window


Hope that makes sense - alot of tabs....
ASKER CERTIFIED SOLUTION
rowansmith

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jacques Bourgeois (James Burger)

I usually do it by letting the user press a function key (I display the function keys at the end of the text on each tab).

To be able to do that at the form level, you first need to set the KeyPreview property of the form to True, so that you will be able to catch all the keys that are pressed while the user is using the form.

Then, in the KeyUp event of the form, I trap the key and display the proper tab, calling it by its name. tacMain is the TabControl.

Private Sub FormMain_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp

'Implements a way to swicth tabs with the keyboard, since the TabControl
'	does not implements shortcut keys
  Select Case e.KeyCode
    Case Keys.F2 : tacMain.SelectedTab = tabProject
    Case Keys.F3 : tacMain.SelectedTab = tabMaterials
    Case Keys.F4 : tacMain.SelectedTab = tabInventory
    Case Keys.F5 : tacMain.SelectedTab = tabSmallParts
    Case Keys.F6 : tacMain.SelectedTab = tabDocumentation
    Case Keys.F7 : tacMain.SelectedTab = tabReports
  End Select

End Sub

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ross13

ASKER
Cheers