Search code examples
vb.netvisual-studio-2010setfocus

Limiting input characters and focusing to the next input box - VB.Net


I have 6 textboxes that I want to use for password validation.

How can I:

  1. limit the number of characters the user can enter into each password field to X-characters; and

  2. ensure that text that are being entered into each field automatically flow into the next input field?

Thank you.


Solution

  • What platform are you using? Given your vb.net 2010 tag, I will assume it is a vb.net application you are working on?

    If this is so, try this:

    Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
    If Textbox1.Text.Length = X then
    Textbox2.Focus()
    End If
    End Sub
    

    The Focus() just takes the focus to the next Textbox control if the condition that the length of the text in Textbox1 equals your set "X" characters target.You can do this for all the textboxes you have on your form.

    I hope this helps you.