I have a windows form which is a countdown Timer. What is the best way for me to pause the timer by pressing the spacebar on the keyboard. I have three buttons on the form for start, pause and stop and res-set. However I also want to pause, restart on press off spacebar. I tried to add a fourth button and then made it hidden on the form and added the following code (changed the EventArgs to KeyEventArgs:
private void button1_Click(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
// Pause the timer.
timer1.Enabled = false;
paused = true;
Start.Enabled = true;
Pause.Enabled = false;
}
However when i try to run this i get the error – No overload for ‘button1_Click matches
delegate System.EventHandler
Is there something I have missed or a better way off doing this.
Any Help/Advice would be appreciated.
The
Clickevent doesn’t take aKeyEventArgs.You’re looking for the form’s
KeyPressevent.