如何删除Windows窗体C#文本框中的警报声音?

问题描述 投票:0回答:1

我在 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()
        {
        }
    }
}

如何解决这个问题???

c# visual-studio winforms
1个回答
0
投票

在 EnterPressed() 事件中使用此代码。

e.SuppressKeyPress = true;
e.Handled = true;
© www.soinside.com 2019 - 2024. All rights reserved.