【发布时间】:2014-09-30 20:37:41
【问题描述】:
当按下键盘上的按钮时尝试触发事件。我已将 Form1 属性设置为也将 KeyPreview 设置为 True。但是,它仍然没有触发,我看不出有什么问题。
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Modifiers == Keys.A)
MessageBox.Show("A pressed");
else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.F1)
MessageBox.Show("Combination of ALt and F1 pressed");
}
【问题讨论】:
-
显示处理程序无济于事,您需要显示附加事件的位置。
-
我讨厌看到没有大括号的
if语句。 -
为什么是
e.Modifiers?为什么不e.KeyCode? -
重复:[stackoverflow.com/questions/3172731/… 如果问题仍然存在,请发布更多详细信息。