1
Reply

Testing whether a key on keyboard is actually pressed

ray dona

ray dona

May 16 2008 1:06 PM
2.8k

I have placed a textbox and other controls on a form. I have the event handler:

private void textbox_KeyPress(object sender, KeyPressEventArgs e)
{
//code to ensure text entered are numbers;
}
How can I test whether a key on the keyboard is actually pressed. If the user presses no key within say 5 seconds I wish to switch focus to another control.

I have tried writing:

if(textbox->Text == "") //then switch focus

in the Tick event of the timer but it does not work.

I would be very grateful for all help.


Answers (1)