C # How to program a tab between controls

I would like to be able to programmatically emulate a navigation keyboard for dialogs.

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

I know about Focus (), but I would prefer to do something that automatically respects the order of the tabs. By emulating keyboard navigation, I don't have to worry about re-developing complex behavior for each type of control.

Does anyone know how to do this?

Thanks!

+7
c #
source share
3 answers

You can use P / Invoke to call the Windows API keybd_event function to simulate a Tab key.

Bonus: you can use your device to enter tabs in a text editor !;)

+3
source share

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

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

+10
source share

In Winforms:

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

To simulate clicking on a tab, I consider the following:

 SendKeys.Send("{TAB}"); 
+9
source share

All Articles