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 matt开发者_如何学Goer 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
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;
}
}
精彩评论