I am using .NET 3.5 framework of VB.NET 2008.
I have some textboxes in my form. I want the tab-like behavior when my user presses ENTER on one of my textboxes. I use
The following code will work.
Public Class Form1
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Convert.ToChar(13) Then
MsgBox("enter key pressd ")
End If
End Sub
End Clas
Public Class Form1
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 pressd ")
End If
End Sub
End Class
Private Sub SomeTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles SomeTextBox.KeyPress
If Asc(e.KeyChar) = 13 Then
MessageBox.Show("Enter pressed!")
e.Handled = True
End If
End Sub
I'm using VB 2010 .NET 4.0 and use the following:
Private Sub tbSecurity_KeyPress(sender As System.Object, e As System.EventArgs) Handles tbSecurity.KeyPress
Dim tmp As System.Windows.Forms.KeyPressEventArgs = e
If tmp.KeyChar = ChrW(Keys.Enter) Then
MessageBox.Show("Enter key")
Else
MessageBox.Show(tmp.KeyChar)
End If
End Sub
Works like a charm!