我正在尝试在 Windows 窗体文本框中捕获 Enter 键。我从教程中得到了这段代码:
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
//
// Detect the KeyEventArg's key enumerated constant.
//
if (e.KeyCode == Keys.Enter)
{
MessageBox.Show("You pressed enter! Good job!");
}
else if (e.KeyCode == Keys.Escape)
{
MessageBox.Show("You pressed escape! What's wrong?");
}
}
但现在我的代码引发了编译/构建错误:
The event 'System.Windows.Forms.Control.Enter' can only appear on the left hand
side of += or -= Line 44 Column 84
一方面我不明白错误信息。另一方面,第 44 行是只有换行符的空白行。
任何建议表示赞赏。
问候。