5
Contributors
4
Replies
26
Views
3 Years
Discussion Span
Last Post by Reverend Jim
0

In the KeyPress event of the textbox1 text box, check for the text length. When text length is equal to 5 set the focus to textbox2 using Focus() method

0

I was having the same problem before.

If Textbox1.TextLength = 5 Then
    TextBox2.Focus
End If

Edited by Reverend Jim: Fixed code formatting

-1

There is a easy process. Take a Form and Two Textbox. At first, Set Form's KeyPreview Property to 'True'. Now write the following code.

Public Class Form1

    Private Sub Form1_KeyUp(sender As Object, e As     System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If Me.ActiveControl Is TextBox1 Then
            If TextBox1.Text.Length >= 5 Then
                TextBox2.Focus()

            End If
        End If
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = ""
        TextBox2.Text = ""
    End Sub
End Class
0

Same mistake here as in two other threads. By filtering at the form level you affect the bahaviour of all textboxes at the top level of the form.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.