-
Jul 8th, 2005, 11:25 AM
#1
Thread Starter
Lively Member
[Resolved]how to auto tab text boxes?
Hi Im new to vb (used to dreamweaver doing all the work !)
Now im in to progging for pc instead of web LOL
right I have 8 text boxes restricted to 4 characters each, have set the tab order but want to curser to move to the next text box automatically after the 4th character has been entered in each box (if that makes sense!)
An example would be on windows xp setup when you type in the product key the curser moves to the next box after the 5 chars for that box have been entered!
Help LOL!
Last edited by polecat; Feb 14th, 2006 at 05:37 PM.
Reason: Resolved
-
Jul 8th, 2005, 12:05 PM
#2
Member
Re: Newbie how to auto tab text boxes?
on textchanged event of textbox1 do the following
Code:
If TextBox1.Text.Length = 4 Then
TextBox2.Focus()
End If
textbox2 will then have the focus
-
Jul 8th, 2005, 12:15 PM
#3
Re: Newbie how to auto tab text boxes?
A slightly better way would be like so:
VB Code:
If TextBox1.Text.Length = TextBox1.MaxLength Then
TextBox2.Focus()
End If
Tg
-
Jul 8th, 2005, 01:31 PM
#4
Re: Newbie how to auto tab text boxes?
this is a single routine that will work for all 8 textboxes, and also will only tab to the next one if they have typed 4 characters, and the cursor is positioned after the last character. This means if they messed up and delete the first character in a textbox and replace it, it will not autotab them (which in my opinion is a good idea)
VB Code:
Private Sub CheckEntry(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, _
TextBox3.TextChanged, TextBox4.TextChanged, _
TextBox5.TextChanged, TextBox6.TextChanged, _
TextBox7.TextChanged, TextBox8.TextChanged
Dim TB As TextBox = CType(sender, TextBox)
If TB.Text.Length = TB.MaxLength Then
'IF YOU WANT IT TO ONLY GO TO THE NEXT TEXTBOX AUTOMATICALLY IF THEY ARE AT
'THE LAST CHARACTER OF THE TEXTBOX, THEN WE NEED TO CHECK THE SELECTIONSTART
'PROPERTY, OTHERWISE YOU CAN REMOVE THAT CHECK, THIS IS USEFUL IF SOMEONE MAKES
'A MISTAKE AND HAS TO GO CHANGE THE VALUE IN THE TEXTBOX
If TB.SelectionStart = 4 Then
Me.SelectNextControl(TB, True, True, False, False)
End If
End If
End Sub
-
Jul 8th, 2005, 02:30 PM
#5
Thread Starter
Lively Member
Re: Newbie how to auto tab text boxes?
WOW ! Guys thanks will try them all and see which works best for me and post back how i get on thankyou for the replys very nice to see a good community spirit!
Thanks
-
Jul 9th, 2005, 03:30 AM
#6
Thread Starter
Lively Member
Re: Newbie how to auto tab text boxes?
I guys they all worked well but decided to use just
If TextBox1.Text.Length = TextBox1.MaxLength Then
TextBox2.Focus()
End If
Just want a way now that only a 1 or a 0 is entered for the 4 characters like 0000 or 0110 etc
-
Jul 9th, 2005, 04:08 AM
#7
Re: Newbie how to auto tab text boxes?
VB Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
'Suppress all key presses that are not "0", "1" or a control character.
e.Handled = (e.KeyChar <> "0"c AndAlso e.KeyChar <> "1"c AndAlso Not Char.IsControl(e.KeyChar))
End Sub
I strongly suggest using kleinma's method to auto-tab as well. It may be slightly (but only slightly) more complex, but it is generic. That means that it will work as is even if you change the tab order, and if you add or remove TextBoxes you just add or remove them to or from the Handles clause.
-
Jun 25th, 2010, 08:45 AM
#8
Junior Member
Re: [Resolved]how to auto tab text boxes?
Hi. Sorry to open his thread.
How can i do this "auto tab" to all forms?
I have about 200 text boxes and i want to use auto tab.
PS - all textboxes have the same lenght of 1 char.
thanks
Using vb.net 2008 with CFv3.8
Last edited by herpez; Jun 25th, 2010 at 08:53 AM.
-
Oct 11th, 2021, 03:05 PM
#9
New Member
Re: Newbie how to auto tab text boxes?
its not working. is this need to add some thing else in the code
this is showing me red code whrn i pasted this
-
Oct 11th, 2021, 11:48 PM
#10
Re: Newbie how to auto tab text boxes?
Originally Posted by shankh
its not working. is this need to add some thing else in the code
this is showing me red code whrn i pasted this
I assume you mean that some of the code is underlined in red. If you're not prepared to specify exactly which code that is and what the error messages are, why should we make any effort to help? We shouldn't have to beg for every scrap of information. If you want help with a problem then explain the problem, fully and clearly. Make an effort to help us help you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|