Jham
Jham

Reputation: 17

Enter key clears content of Textbox

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles TextBox1.KeyPress

    If Asc(e.KeyChar) = Keys.Enter Then
        TextBox2.Focus()
    End If

End Sub

That above code was my codes for moving to another textbox once the textbox1 has a value Or should I say Once i input a value inside the textbox1 and use enter key it should move to TextBox2 but it happened that when you use enter key, textbox1 value has been cleared. My textbox tool is in MultiLine that's why it always happen.

Upvotes: 0

Views: 2386

Answers (1)

user5713158
user5713158

Reputation:

Instead of using the KeyPress event try using KeyDown, and in the code for TextBox1_KeyDown enter the following

If e.Keys = Keys.Enter
    TextBox_2.Focus()
    e.Handled = true
End If

Upvotes: 2

Related Questions