Using VS2008, Windows Forms Application
In a TextBox::KeyDow n event I check to see if the Enter Key has been pressed, and if so, I perform some action then attempt to select all of the text using SelectAll(), as follows:
It works as expected if I manually enter text into the TextBox then press enter, but if I use a barcode reader to enter the text (with a <CR>), the PerformSomeActi on() method executes but the SelectAll() method appears to not select the text. I'm guessing the difference is the timing between characters.
To get passed the issue I changed to code to use a Timer as follows:
This works if the Timer Interval is set to a value greater than 10ms.
Note: the PerformSomeActi on() method is irrelevant.
Can someone explain the timing involved and why, without the Timer, it doesn't work?
In a TextBox::KeyDow n event I check to see if the Enter Key has been pressed, and if so, I perform some action then attempt to select all of the text using SelectAll(), as follows:
Code:
private void SelectAllTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (Keys.Enter == e.KeyCode)
{
PerformSomeAction();
SelectAllTextBox.SelectAll();
}
}
To get passed the issue I changed to code to use a Timer as follows:
Code:
private void SelectAllTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (Keys.Enter == e.KeyCode)
{
PerformSomeAction();
HackTimer.Start();
}
}
private void HackTimer_Tick(object sender, EventArgs e)
{
HackTimer.Stop();
SelectAllTextBox.SelectAll();
}
Note: the PerformSomeActi on() method is irrelevant.
Can someone explain the timing involved and why, without the Timer, it doesn't work?
Comment