PrimalForms/PowerShell – Event Behavior: Tab Key or Enter Key

Which captured the Event Behavior: KeyPress which was used to trigger an action after the Enter Key was pressed.

During a project to allow our admins to change the manager field in our AD LDS Identity Store I was coding a Textbox to be triggered with the tab key, but low and behold they TAB key is not captured by default by the KeyDown, KeyPress or KeyUp Events.

Certain keys, such as the TAB, RETURN, ESC, and arrow keys are handled by controls automatically. To have these keys raise the KeyDown event, you must override the IsInputKey method in each control on your form. The code for the override of the IsInputKey would need to determine if one of the special keys is pressed and return a value of true. Instead of overriding the IsInputKey method, you can handle the PreviewKeyDown event and set the IsInputKey property to true.

Note the IsInputKey method must be set per control, so there is no need to turn it back off for other controls on the same form.

So in this example I start with a basic form with two labels, two textboxes, and a status bar to show when the TAB or ENTER keys are captured.

For the Event Behaivior: PreviewKeyDown for $textbox1 I setup the following code: