Does anyone know why the KeyPress Event doesn't get fired when the user presses a down arrow? I have to look for it in the KeyDown event. Is this just something that I am doing wrong?
According to the documentation of the KeyPress event (assuming you are using WinForms):
The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events.
The down arrow key isn't a character key, so this event shouldn't be raised for it.
Use KeyDown instead
Public Class Form1
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
Debug.WriteLine(e.KeyData.ToString + " KeyDown")
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Debug.WriteLine(e.KeyChar.ToString + " KeyPress")
End Sub
End Class
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