Respond to user press Button VB.NET 2005

10 Sep

Reference: http://www.daniweb.com/forums/thread60968.html

This function works for do something if the user Click the Enter Key, I take some functionality that saves some time to the user; Its always good when you respect users time as much as possible in the project designs.

Private Sub TextBox1_Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, TextBox2.KeyDown
If e.KeyCode = Keys.Tab Then
If sender.Name = “TextBox1” Then
TextBox2.Focus()
e.Handled = True
ElseIf sender.Name = “TextBox2” Then
TextBox1.Focus()
e.Handled = True
End If
End If
End Sub

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress, TextBox2.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
If sender.name = “TextBox1” Then
TextBox2.Focus()
e.Handled = True
ElseIf sender.name = “TextBox2” Then
TextBox1.Focus()
e.Handled = True
End If
End If
End Sub

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: