TextBox Focus
-
In My Application I have Three textboxes for phone number to maintain the format as 3-3-4.Once the user enters the first 3 numbers of a phone number the focus should automatically go to nextbox How can I do it in C# chanti
-
In My Application I have Three textboxes for phone number to maintain the format as 3-3-4.Once the user enters the first 3 numbers of a phone number the focus should automatically go to nextbox How can I do it in C# chanti
on the textbox1 keyup event u can check the length of text entered in textbox by following way textbox1.text.length and then check the condition if(textbox1.text.length==3) textbox2.focus(); same way you can put same condition for textbox2 on its keyup event to transfer focus on textbox3.
rahul
-
In My Application I have Three textboxes for phone number to maintain the format as 3-3-4.Once the user enters the first 3 numbers of a phone number the focus should automatically go to nextbox How can I do it in C# chanti
Hi, you could do this by binding the textboxes KeyUp-Event. The first argument passed to the eventhandler is the triggering object (in this case the textbox where the user has written in). the code for the eventhandler could look like: TextBox mytxtbox = (TextBox) sender; if (mytxtbox.Text.Length == 3) theNextTextBox.Focus(); if you need further assistance feel free to ask :)
-
In My Application I have Three textboxes for phone number to maintain the format as 3-3-4.Once the user enters the first 3 numbers of a phone number the focus should automatically go to nextbox How can I do it in C# chanti
hi Chanti, You can do this by more than one way. The most easy way that I could think of right now is to set the maximum lenght property of the three text boxes (lets say firstTextBox, secondTextBox, thirdTextBox) to 3-3-4 simultanuously. After doing so the program want allow u to type more than 3 digits in the first text box but wont take u to the next one. So u have to fire an event of that text box. The event that u should fire is the TextChanged event and write inside this method the following code: if (firstTextBox.Text.Length == 3) { secondTextBox.Focus(); } This will take the focus and the next character to the secondTextBox. And u can do this for the other textboxes too. If you need any help in any other issue, don't be shy to add me at the following MSN address: jamilaboukhalil@hotmail.com or you can just send a mail. Jamil Abou khalil
-
hi Chanti, You can do this by more than one way. The most easy way that I could think of right now is to set the maximum lenght property of the three text boxes (lets say firstTextBox, secondTextBox, thirdTextBox) to 3-3-4 simultanuously. After doing so the program want allow u to type more than 3 digits in the first text box but wont take u to the next one. So u have to fire an event of that text box. The event that u should fire is the TextChanged event and write inside this method the following code: if (firstTextBox.Text.Length == 3) { secondTextBox.Focus(); } This will take the focus and the next character to the secondTextBox. And u can do this for the other textboxes too. If you need any help in any other issue, don't be shy to add me at the following MSN address: jamilaboukhalil@hotmail.com or you can just send a mail. Jamil Abou khalil
yes this is right solution the previous one does fail when we keep the key pressed :):)
-
yes this is right solution the previous one does fail when we keep the key pressed :):)
-
yes this is right solution the previous one does fail when we keep the key pressed :):)
Yea right, that's the negative side about the keydown/keyup/keypressed events.u don't know which key is pressed. Anyway hope that i did benifit u. Feel free to contact me at my MSN address jamilaboukhalil@hotmail.com. Take care