Set Focus

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi all, if you have two text boxes on a form and the first only allows 10
characters, how do you set the focus to the second box after the 10th
character is entered in the 1st box?

Thanks in advance.
 
Mike said:
Hi all, if you have two text boxes on a form and the first only allows 10
characters, how do you set the focus to the second box after the 10th
character is entered in the 1st box?

Thanks in advance.

Use one of the Key events, probably KeyUp, to calculate the current
length of the Text property. Once it hits 10 characters, switch the
focus by setting the Focus property of the second textbox.
 
Hi Mike,

Here is the code:

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TextBox1.TextChanged
If Me.TextBox1.Text.Length = 10 Then

Me.TextBox2.Focus()
End If
End Sub

I used the text changed event. Using key up and down will need more
work since you need to know what keys were pressed.

Ahmed


Mike wrote:
 
Mike said:
I don't know what a key event is. Can you give an example?

In the IDE Code window for the Form, select the text box control in the
left hand drop down. In the right hand drop down, there will be a list
of available events. Select KeyUp (or whatever) and a declaration for
that event will be inserted in your code. Just add your length
checking code there.

Or as others have posted, there are several events that can accomplish
this task, including the TextChanged event.
 
Back
Top