views:

87

answers:

1

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

+4  A: 

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;
    }
}
SLaks
Excellent. That should work.
Robert Harvey
Tested and working perfectly. I only changed e.KeyCode by e.KeyValue. Thanks.
Jonathan