No button click - enter type

ibanezFreak87

Member
Joined
Mar 6, 2006
Messages
8
Programming Experience
Beginner
How would I be able to code something to happen when I press "enter" on my keyboard?
i.e. I want the user to input a number in a textbox and then press enter on the user's keyboard and then for the program to do.....
 
You set the TextBox property AcceptReturn=True, and handle the KeyUp event to see if e.KeyCode=Keys.Return
 
On form: KeyPreview = True

VB.NET:
    Private Sub TextBox1_keypress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
            'do something - enter was pressed.
        End If
    End Sub
 
btw, DavidT, the KeyPreview is only required for catching the keys events for the form itself, it's not related to the contained controls keys events.
 
Back
Top