Detecting when the Enter key is pressed?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sc5502
    New Member
    • Jun 2014
    • 102

    Detecting when the Enter key is pressed?

    Visual Basic - Visual Studio - 2016

    I have a form with text boxes on it. In one of the text boxes I want to detect when the user hits the enter key so I can preform a routine.

    How do you detect when a user presses the Enter key in a text box?
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    Simply use the TextBox1_KeyDow n event, with code similar to the following:

    Code:
        Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
            If e.KeyCode = Keys.Enter Then
                MsgBox("Enter Key Pressed!")
            End If
        End Sub

    Comment

    Working...