Monday, April 6, 2009

How to enter the values in textboxes continously without placing the mouse pointer

Below is the trick that does it
U have to fire the keyup press event so whenever the key is pressed, the event will be fired and the text box focus will be changed according to the maximum length of the textbox.

C# Code
if lets suppose u have to enter the SSN in the three text boxes
Enter the SSN : [123]-[23]-[1234]

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
if (textBox1.Text.Length == 3)
{
textBox2.Focus();

}
}

private void textBox2_KeyUp(object sender, KeyEventArgs e)
{
if (textBox2.Text.Length == 2)
{
textBox3.Focus();
}
}

private void submit_Click(object sender, EventArgs e)
{
System.Console.WriteLine(textBox1.Text + textBox2.Text + textBox3.Text);
}

hope this helps
shoot me at nishant.pacific@gmail.com

No comments: