Yesterday I wrote about how to capture a carriage return key press. That is awesome and everything, but I also like to use TAB, The problem is that the KeyPress event does not like the TAB key. The KeyDown does if you also include the PreviewKeyDown event. OK, let’s use the same setup as yesterday. Just a form and a text box.
For the text box add the PreviewKeyDown and KeyDown events.
In the PreviewKeyDown event, you only need to add one line of code. In the KeyDown event, we do the same thing as yesterday. This time we use the KeyValue property and the ASCII code of 9. The rest is the same as yesterday.
The green arrows show you the code that I added. Just run it and press TAB. The text box will turn blue. Again, this is where you would place the action that you want to take place when TAB is pressed.