我正在做反应测试。当我将我的项目复制到其他项目(带菜单等)时,计时器和Keydown不起作用。我的朋友用一个Eventhandler解决了计时器,但是keydown仍然无法正常工作。
private void Button1_KeyDown(object sender, KeyEventArgs e)
{
char c = Convert.ToChar(e.KeyCode);
if (c == 82)
{
this.BackColor = Color.LightBlue;
extime.Stop();
long rtime = extime.ElapsedMilliseconds;
timer1.Enabled = false;
button1.Text = Convert.ToString(rtime) + Environment.NewLine + "milliseconds";
button1.Visible = true;
extime.Reset();
}
}
这不起作用:
private void Reactiontest_Load(object sender, EventArgs e)
{
button1.KeyDown += Button1_KeyDown;
}
答案 0 :(得分:1)
您是否尝试过将keydown_event放在表单中而不是按钮?