1
Answer

Testing whether a key on keyboard is actually pressed

Ask a question
ray dona

ray dona

16y
2.8k
1

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)