
August 2nd, 2007, 12:55 PM
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 1
Time spent in forums: 4 m 43 sec
Reputation Power: 0
|
|
|
C# Textbox Focus question
Hello,
I have been searching around trying to find any information on how to use the arrow keys to change the focus on a textbox.
I am creating a program that has 3 text boxes that would contain a phone number. At the moment I have the focus change when the TextBox Length is equal 3 ... but I would like to be able to also use the keyboard to change the focus of the box. Say the user would make a mistake (typo) and want to go back by using the left arrow key...
But... I also would like it NOT to switch from 1 box to the other unless it is at the end of the textbox. If that makes sense. I want the arrow key to move through the entered numbers then switch to the next text box. So if they have entered their entire phone number and notice the second number is wrong... by hitting the arrow key it will take them through the last 4 numbers, then skip to the next text box, then move through those 3 numbers then skip to the next box, then move to his number he wants to change.
I hope this makes sence to you.
Here is a clip of what I have so far.
Code:
private void txtPhn1_TextChanged(object sender, EventArgs e)
{
if (txtPhn1.TextLength == 3)
{
txtPhn2.Focus();
}
}
private void txtPhn2_TextChanged(object sender, EventArgs e)
{
if (txtPhn2.TextLength == 3)
{
txtPhn3.Focus();
}
else
{
if (txtPhn2.TextLength == 0)
{
txtPhn1.Focus();
}
}
}
private void txtPhn3_TextChanged(object sender, EventArgs e)
{
if (txtPhn3.TextLength == 0)
{
txtPhn2.Focus();
}
}
private void btn1_Click(object sender, EventArgs e)
{
StatusMsg("Phone Number: [ " + txtPhn1.Text + "-" + txtPhn2.Text + "-" + txtPhn3.Text + " ]");
}
Ty In advance
|