Link to home
Start Free TrialLog in
Avatar of ross13
ross13Flag 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
Avatar of Giuseppe Pizzuto
Giuseppe Pizzuto
Flag of Italy image

what method will the user "use" ? Using TAB button, some function/key (F1..F12), some combination on keys... ???
Avatar of rowansmith
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
Avatar of rowansmith
rowansmith

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of ross13

ASKER

Cheers