Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How to programmatically tab between controls

Tags:

c#

I would like to be able to programmatically emulate the keyboard navigation for dialog boxes.

I have a custom hardware device with a keypad that I would like to use for dialog box navigation.

I know about Focus(), but I'd rather do something that automatically respected the tab order. By emulating the keyboard navigation I don't have to worry about re-inventing complex behavior for each type of control.

Does anyone know how to do this?

Thanks!

like image 300
NXT Avatar asked Jul 24 '09 18:07

NXT


2 Answers

For Winforms, you want want the Control.GetNextControl() method

For WPF, you want the UIElement.MoveFocus() method

like image 129
Randolpho Avatar answered Oct 08 '22 21:10

Randolpho


In Winforms:

Control nextControl = this.GetNextControl(myControl, true);

To simulate a tab press, I believe it's the following:

SendKeys.Send("{TAB}");
like image 32
Will Eddins Avatar answered Oct 08 '22 21:10

Will Eddins