在 TextBox 上处理 KeyUp 时静音叮声

Silence ding sound when handling KeyUp on TextBox

我正在使用它来允许光标前进到 WinForm 上的下一个 TextBox:

private void GoToNextControl(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Enter)
    {
        this.SelectNextControl((Control)sender, true, true, true, true);
    }
}

如果我按 enter 时没有 "ding" 声音,这将完美运行。我怎么会"silence"叮的?

在处理程序中将 SuppressKeyPress 设置为 true 应该这样做:

private void GoToNextControl(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Enter)
    {
        this.SelectNextControl((Control)sender, true, true, true, true);
        e.SuppressKeyPress = true;
    }
}

确保您的处理程序连接到 KeyDown 事件,因为这在 KeyUp 中不起作用。

"Ding" 声音来自未处理的表单事件。在您的表格上: 1.添加一个按钮,设置它的Visible 属性 为 false 2. 向该按钮添加 OnClick 事件处理程序。保持方法为空 3. 将Form的AcceptButton 属性设置为新建按钮。 而已。 "Ding"会消失