Reputation: 693
I am using 2 text boxes which will input int digits to max length of 3. How can I pass a mouse pointer from first text box to the second one when 3 digits were entered?
I am trying to do it on TextChange event, but I'm not sure how to check when 3rd digit was checked...
public partial class PingIPRange : Form
{
public PingIPRange()
{
InitializeComponent();
txtF1.TextChanged += new EventHandler(NextField);
txtF2.TextChanged += new EventHandler(NextField);
}
private void NextField(object sender, EventArgs e)
{
// Well, I have no idea how to start with this...
}
}
Upvotes: 0
Views: 2234
Reputation: 2488
Like in the previous answers, you probably want TextBox.Focus()
, but in case you actually wanted to move the pointer:
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (((TextBox)sender).Text.Length == 3) { Cursor.Position = textBox2.Location; }
}
Upvotes: 0
Reputation: 9209
Are you sure that you want the mouse pointer to move rather than the "carot" for typing, which is standard practice.
You'll want to check the string length within the text box as each character is entered and then set the Focus to the new text box.
Upvotes: 3
Reputation: 25595
Once txtF1.Text.Length == 3
, you can use txtF2.Focus()
in order to 'move the cursor' to the 2nd textbox
EDIT:
private void NextField(object sender, EventArgs e)
{
if (txtF1.Text.Length == 3) // Textbox contains 3 characters, you DO NEED to validate your input.
txtF2.Focus();
}
Upvotes: 3