tags:

views:

349

answers:

2

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. I was just wondering if this was something that I was doing wrong or not?

+9  A: 

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.

Andy
+1  A: 

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
Grant