I was working in windows forms, and I wanted to do the Action() when enter is pressed. And it work’s but there was an alert sound.
This is my code:
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()
{
}
}
}
How to fix this???
New contributor
new csharp’er is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
0
Use this code in the EnterPressed() event.
e.SuppressKeyPress = true;
e.Handled = true;
1