Reputation: 45
I've created a stock locater/mover program. The scenario sequence is as follows:
How do I auto move the cursor into textBox2 after textBox1 has been populated with a QR Code?
Please note the QR codes vary in length. This prevents me from using textBox max length. I've currently tried the following:
private void textBox1_TextChanged(object sender, EventArgs e)
{
//part number textbox
var partNumber = textBox1.Text;
partNumber = partNumber.TrimEnd('\r', '\n');
if (textBox1.Text!=null)
{
textBox1.Select();
}
else
{
textBox2.Select();
}
}
Using the aforementioned code, the first character of the QR code is input into textBox1 and the remaining characters are input into textBox2. The desire is to have all the QR code characters in textBox1 and then have the cursor change focus to textBox2.
Upvotes: 1
Views: 347
Reputation: 45
Solution;
private void textBox1_KeyPress(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
textBox2.Select();
}
}
then went to the properties of textBox1 and set the 'KeyDown' to textBox1_KeyPress under 'Events' and it works.
Upvotes: 1
Reputation: 938
A similar issue has been described in another question here on SE.
The following answer, posted by esskar might be of interest to you. Since the scanner will probably take only an instant to scan the QR code into the TextBox, you might use the technique in that answer to start a timer when TextChanged fires. I'd set the interval of the Timer at around 500ms, that should be enough, and once it fires you can be pretty sure that the QR code is inside the TextBox.
Obviously this isn't a perfect solution, since in some cases the scanner might lag or simply be unable to deliver the QR code in that time-frame for whatever reason.
You will need to implement a check for common QR code length and validate the code before you go on.
To be clear: There's no need to create a new type of TextBox. Just start a Timer when TextChanged is fired.
Upvotes: 0