By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,558 Members | 1,177 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,558 IT Pros & Developers. It's quick & easy.

Detecting when the Enter key is pressed?

100+
P: 102
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?
May 17 '17 #1
Share this Question
Share on Google+
1 Reply


100+
P: 299
Simply use the TextBox1_KeyDown event, with code similar to the following:

Expand|Select|Wrap|Line Numbers
  1.     Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
  2.         If e.KeyCode = Keys.Enter Then
  3.             MsgBox("Enter Key Pressed!")
  4.         End If
  5.     End Sub
May 18 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.