Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcuts to change the active tab in my application

My application has a main window that contain a TabControl with about 7 TabItems. Inside each tabItem I put a UserControl.

I would like that (no matter the active tab, or control) when the user press a combination of keys then user-interface jumps to a specific tab. that is, The same behavior that Firefox: alt+1 goes to the first tab, alt+n goes to the N tab.

How can I achieve this? or... what should I start searching?

I can't show you any code because the problem is that I don't know how to start.

Thanks

like image 270
Jonathan Avatar asked Nov 11 '09 21:11

Jonathan


People also ask

How do you instantly change a tab?

Press Alt + Tab to move between windows. Right-click on a tab and select Move tab to another window.

What are the shortcut keys to switch to different active applications in your computer?

Shortcut 1:Press and hold the [Alt] key > Click the [Tab] key once. A box with screen shots representing all of the open applications will appear. Keep the [Alt] key pressed down and press the [Tab] key or arrows to switch between open applications. Release the [Alt] key to open the selected application.

What is Ctrl Shift P?

Ctrl + Shift + P. Play selected item.

What is Ctrl Shift L?

2. CTRL+SHIFT+L – Turn on/ off filters.


1 Answers

Set the form's KeyPreview property to true, override the form's OnKeyDown (or OnKeyUp) method, and put in the following code: (Untested)

protected override void OnKeyDown(KeyEventArgs e) {
    base.OnKeyDown(e);
    if (e.Alt && e.KeyCode > '0' && e.KeyCode <= '9') {
        tabControl.SelectedIndex = (int)(e.KeyCode - '1');
        e.Handled = true;
    }
}
like image 162
SLaks Avatar answered Oct 18 '22 10:10

SLaks