cmdolcet
asked on
How to capture a TAB key press in a Key Press Event
How can I capture a Tab key press in a Key Press Event Arg in vb 2005?
ASKER
But its the Key Press Event that is not picking the Keypress even up.
What control are you using the event on?
ASKER
Its a Key Press Even Args
Are you trying to detect it in a text box, or on the form, or somewhere else?
ASKER
I have a textbox on the form, however any other key I press is detected (BACKSpae,Enter,Shift, and letter or numerical keys) just not the TAB key.
Use the PreviewKeyDown event, and add in if block that I have in the example below. The PreviewKeyDown will capture the tab key and the isinputKey = true will treat is like a normal key press an not like the normal function of tab in a form. Once that event fires it will fire the keypress event next. Hope this helps.
Private Sub TextBox1_PreviewKeyDown(sender As Object, e As PreviewKeyDownEventArgs) Handles txtQty1.PreviewKeyDown
If e.KeyCode = Keys.Tab Then
e.IsInputKey = True
End If
End Sub
ASKER
The problem with that is the textbox is created dynamically on the form. Any ideas from that how I can use the PreviewKeyDown event?
How did you accomplish this before with the keypress event? You stated in previous comments that the keypress event was picking up other keys for the text box?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window