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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

how to force a text box to always be in focus. 6
Moving Focus 2
contextmenu 2
Setting focus doesn't work 3
How to Set Focus 2
Focus 7
MaxLength of textbox and Focus change 3
Quick MDI form question 1

Back
Top