开发者

Capture spacebar press to pause Timer C#

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 开发者_如何学Goit 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 Click event doesn't take a KeyEventArgs.

You're looking for the form's KeyPress event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜