我在 Windows 窗体中工作,我想在按下 Enter 时执行 Action() 。它可以工作,但有警报声。
这是我的代码:
namespace PasswordManager
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void EnterPressed(object sender, KeyEventArgs e)
{
if (textBox1.Text != "" && e.KeyCode == Keys.Enter) // if Enter is pressed
{
Action();
}
}
private void Action()
{
}
}
}
如何解决这个问题???
在 EnterPressed() 事件中使用此代码。
e.SuppressKeyPress = true;
e.Handled = true;