Form1_KeyDown不工作
private void Form1_KeyDown(object sender, KeyEventArgs e) { if (listBox1.Items.Contains(e.KeyCode)) { listBox1.Items.Remove(e.KeyCode); listBox1.Refresh(); timer1.Interval -= 10; difficultyProgessbar.Value = 800 - timer1.Interval; stats.update(true); } else { stats.update(false); } correctLabel.Text = stats.correct.ToString(); missedLabel.Text = stats.missed.ToString(); totalLabel.Text = stats.total.ToString(); accuracyLabel.Text = stats.accuracy.ToString(); } private void timer1_Tick(object sender, EventArgs e) { //Add a random key to Listbox listBox1.Items.Add((Keys)random.Next(65, 90)); Application.DoEvents(); if (listBox1.Items.Count > 7) { listBox1.Items.Clear(); listBox1.Items.Add("Game Over"); timer1.Stop(); } }
当我运行我的应用程序时, timer1_Tick
事件正常工作,但是当我按任意键时, Form1_KeyDown
事件不会执行。 缺少什么? 为什么Key_Down
事件永远不会触发? 谢谢
Keydown在Control with Focus中发射。
要在表单级别接收它,您需要设置属性。 表格的KeyPreview = True
上述就是C#学习教程:Form1_KeyDown不工作分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1017119.html