我正在尝试构建一个具有按钮的程序,每次单击该按钮时,它都会移动按钮并添加到分数中。但是,我正在尝试禁用 Enter 键,或者在按下时禁止该命令。这是我到目前为止所拥有的
private void button1_Click(object sender, EventArgs e, KeyEventArgs k)
{
if (k.KeyCode == Keys.Enter)
{
k.SuppressKeyPress = true;
}
score = score + 10;
timesClicked++;
int rand1 = RandomNumber(1, 400);
int rand2 = RandomNumber(1, 400);
button1.Location = new Point(rand1, rand2);
toolStripScore.Text = ("Your score is " + score);
toolStripClicks.Text = ("You've clicked the button{0} times " + timesClicked);
winCheck();
}
这是我添加的以防止输入键进入。
if (k.KeyCode == Keys.Enter) { k.SuppressKeyPress = true; }
但是它会产生错误...“'button1_Click' 没有重载匹配委托'System.EventHandler'”当单击以显示位置时,它会打开 Form1.Designer 的代码并指向这一行。“this.button1.Click += new System.EventHandler(this.button1_Click);”
任何有关解决此问题的帮助将不胜感激。