Capture Tab Key in dot net Textbox
Although it would seemingly be a simple task to capture a tab to perform some special operation in a form like say – begin a processing thread or something like that, it is not necessarily straight forward.
First Thoughts
Capture Tab Key in dot net Textbox – Details
My first thought was just to right click and add a keyup handler, which did not do the trick as it appeared that the event was not being generated. My second thought was to try the key press and keydown events which did not trigger either. Eventually I figured out the event capture, but then I had to figure out how to prevent the tab from appearing in the Textbox itself.
Solution
- Look for the property called AcceptsTab in design view and make sure that value is set to true
- Look for the property called Multiline in design view and make sure that value is set to true
- Add event Keypress with the following snippet.
C#
if (e.KeyChar == 0x09) { e.Handled = true; }
VB.net
If e.KeyChar = Chr(9) Then e.Handled = True End If
Really liked what you had to say in your post, Capture Tab Key in dot net Textbox, thanks for the good read!
— Alberto
http://www.terrazoa.com