Achab
Achab

Reputation: 9

Converting KeyPress Event from VB6 to VB.NET

I need to convert this language (written in VB6) to VB.NET:

Private Sub txt1_KeyPress(KeyAscii as Integer)
   If KeyAscii=13 Then
       XXX=CStr(txt1.Text)
       txt2.SetFocus
   End If
End Sub

I just wanted that by pressing the Enter key (KeyAscii=13) the txt1 sets the Focus to the next text box txt2.

Can someone help me? Thanks.

Upvotes: 0

Views: 2059

Answers (1)

Antagony
Antagony

Reputation: 1780

Try this:

Private Sub Txt1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles Txt1.KeyPress
    If e.KeyChar.ToString = ChrW(Keys.Enter) Then
        Txt2.Focus()
        e.Handled = True
    End If
End Sub

Upvotes: 1

Related Questions