Click here to Skip to main content
15,078,444 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a form with many textboxes. Is there a vb.net code to move the mouse pointer(cursor location) to the right(next textbox) after filling one textbox with (say 3 characters)?
Posted
Updated 7-Jun-13 7:45am
v6
Comments
   
What "pointer"? Do you want to move the keyboard focus?
System.Windows.Forms? Tag: "WinForms".
—SA

Assuming Winforms, just handle the TextChanged event, check the length and call the Focus method on the other textbox:
VB
Private Sub textBox1_TextChanged(sender As Object, e As EventArgs)
    If textBox1.Text.Length >= 3 Then
        textBox2.Focus()
    End If
End Sub


If this is web based, then you can't do it VB - you need to use Javascript instead.
   
v2
Comments
Prasad Khandekar 7-Jun-13 11:18am
   
Seems to be the solution dflo is looking for. (Probably a credit card number or similar entry form). +5
Yes, there is. For instance
VB
Private Sub txbFirst_TextChanged(sender As Object, e As EventArgs) Handles txbFirst.TextChanged
  If txbFirst.Text.Length >= 3 Then
    txbSecond.Focus()
  End If
End Sub
   
Comments
Prasad Khandekar 7-Jun-13 11:17am
   
Seems to be the solution dflo is looking for. (Probably a credit card number or similar entry form). +5
CPallini 7-Jun-13 11:33am
   
Thank you.
dflo 7-Jun-13 11:22am
   
Thanks for your understanding despite my poor question!
CPallini 7-Jun-13 11:33am
   
You are welcome.
You hardly can get much help until you learn involved concepts and proper terminology. It's too hard to understand what you are trying to do, and it's possibly that you don't quite understand it yourself, at least it looks so from your question.

By on my guesswork, what you really need is System.Windows.Forms.Control.SelectNextControl:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.selectnextcontrol.aspx[^].

If it's not quite what you want, please don't blame be, better learn asking questions more accurately.

—SA
   
Or for a generic handler:

VB
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged, TextBox4.TextChanged

    If DirectCast(sender, TextBox).Text.Length >= 3 Then
       DirectCast(sender, TextBox).Parent.SelectNextControl(ActiveControl, True, True, True, True)
    End If

End Sub
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900