While inside a textbox, i can get the enter and escape keypress but i cant get the arrows (up down left right) key press. Instead it moves the cursor inside the textbox. I guess i have to override this but how? I need to be able to catch these events only when im inside the textbox, ....so a form listener is out of the question(?)
Private Sub txtMytext_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles Mytext.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
MsgBox("Enter pressed!")
End If
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Escape) Then
MsgBox("Escape pressed!")
End If
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Up) Then
MsgBox("Up key pressed!") ' this never fires :(
End If
End Sub
posting an answer to my own question, after helpful comments from DatVM and MrPaulch:
Instead of KeyPress i used the KeyDown event:
Private Sub txtMyText_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtMyText.KeyDown
If e.KeyCode = Keys.Up Then
MsgBox("UP")
End If
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With