Move cursor to next textbox
-
Hi all I have 3 textbox in the form and i make the Property MaxLength to 3 and i want that when i enter 3 letter in first textbox the cursor move auto to the next and so on
-*-*-*-*-*-*-*-*-* To Be Or Not To Be (KARFER) -*-*-*-*-*-*-*-*-*
capture the keypress event, and when the third key is pressed call the Focus() method of the next textbox. To be clear, don't count keypresses, check the length of the string. And keyup may be a better one to use.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Hi all I have 3 textbox in the form and i make the Property MaxLength to 3 and i want that when i enter 3 letter in first textbox the cursor move auto to the next and so on
-*-*-*-*-*-*-*-*-* To Be Or Not To Be (KARFER) -*-*-*-*-*-*-*-*-*
Use KeyPress event of first text box to check length text and if it is three move focus to second text box. Such as – ------------------------------- Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If Me.TextBox1.Text.Length = 3 Then e.Handled = True Me.TextBox2.Focus() End If End Sub ------------------------------- -Ajay.
------------------------- www.componentone.com -------------------------
-
Use KeyPress event of first text box to check length text and if it is three move focus to second text box. Such as – ------------------------------- Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If Me.TextBox1.Text.Length = 3 Then e.Handled = True Me.TextBox2.Focus() End If End Sub ------------------------------- -Ajay.
------------------------- www.componentone.com -------------------------
Thanks for repeating my answer, only what you've posted, requires pushing a fourth key, which never appears in either textbox, in order to move focus.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Use KeyPress event of first text box to check length text and if it is three move focus to second text box. Such as – ------------------------------- Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If Me.TextBox1.Text.Length = 3 Then e.Handled = True Me.TextBox2.Focus() End If End Sub ------------------------------- -Ajay.
------------------------- www.componentone.com -------------------------
If you replace Textbox1 with sender then you can handle both TextBox1 and TextBox2 with the same method
Never underestimate the power of human stupidity RAH
-
If you replace Textbox1 with sender then you can handle both TextBox1 and TextBox2 with the same method
Never underestimate the power of human stupidity RAH
Except you would be better to write a class to handle this, so you can easily set what textbox2 is, for each textbox.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Except you would be better to write a class to handle this, so you can easily set what textbox2 is, for each textbox.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Ok I'll bite - why. Having a single method to service the multiple textboxes seems the most efficient (assuming you do not want to reuse it outside this form) Ah, I had to read that 5 times to get it - set the destination/next textbox. I would have thought either hard code the target or use the form tab order to identify the next control. Oh sh;t now I remebered why I hate these things, I just envisaged a complete UI class to handle all the silly operations that can crop up shudder.
Never underestimate the power of human stupidity RAH
-
Ok I'll bite - why. Having a single method to service the multiple textboxes seems the most efficient (assuming you do not want to reuse it outside this form) Ah, I had to read that 5 times to get it - set the destination/next textbox. I would have thought either hard code the target or use the form tab order to identify the next control. Oh sh;t now I remebered why I hate these things, I just envisaged a complete UI class to handle all the silly operations that can crop up shudder.
Never underestimate the power of human stupidity RAH
Yeah, I guess it depends on if you expect to reuse it across several forms, etc. If you had three textboxes and that was it, you could just have a switch statement or use the tag on the textbox to identify the next one or something.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )