Press Enter in TextBox to Trigger Click Event in VB.NET
Submitted by donbermoy on Friday, July 31, 2015 - 15:10.
This is a very simple tutorial of mine yet a very useful one. This is a program that when you press the enter key in the textbox, it will trigger to have the click event of the button using the VB.NET programming language.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Next, add only one Button named Button1 and a textbox named TextBox1 on the Form.
3. Now, we will do the coding!
First, we will put a code statement on the Click event of our Button. We will just put a messagebox there.
Now, for pressing the enter key of the textbox we will use the Keypress Event of the TextBox.
The e.KeyChar emphasizes to get the key character that was pressed by the user and the chr(13) indicates the Enter Key. So meaning if pressing the Enter key using this code will trigger to run the Button's Click Event. The 'Me' as part of the Button1_Click parameters indicates that the clicking will be in the current form.
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- End Sub
- Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
- 'Runs the Button1_Click Event
- Button1_Click(Me, EventArgs.Empty)
- End If
- End Sub
Output:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISwareComments
Add new comment
- Add new comment
- 10795 views