Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing whether a key on keyboard is actually pressed

Status
Not open for further replies.

raydona

Programmer
May 12, 2005
27
GB
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.
 
Try:

Code:
private void TextBox1_GotFocus(object sender, System.EventArgs e) 
{ 
    
    Timer1.Start(); 
    
} 

private void TextBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) 
{ 
    
    Timer1.Stop(); 
    Timer1.Start(); 
    
} 

private void Timer1_Tick(object sender, System.EventArgs e) 
{ 
    
    TextBox2.Focus(); 
    Timer1.Stop(); 
    
}


Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top