我已成功分配 ENTER 键来触发 button1 点击事件。当我按 ENTER 时,它应该打开“开始菜单”表单。然而,它做了两次。不止一次。我在我的代码中找不到问题,有人可以帮助我吗?
这是我的代码:
public Login()
{
InitializeComponent();
this.textBox1.KeyDown += new KeyEventHandler(textBox1_KeyDown);
}
private void button1_Click_1(object sender, EventArgs e)
{
if (somethingsomething == true)
{
Startmenu sm = new Startmenu();
sm.Show();
}
else
{
MessageBox.Show("something");
}
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
button1.PerformClick();
e.Handled = true;
}
}