【问题标题】:Silence ding sound when handling KeyUp on TextBox [duplicate]在 TextBox 上处理 KeyUp 时静音 ding 声音 [重复]
【发布时间】:2015-03-23 01:56:26
【问题描述】:

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

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

如果不是在我按 Enter 时发出“叮”的声音,这将完美无缺。我怎么能“沉默”这个叮当声?

【问题讨论】:

  • @Mitch - 我看过那个帖子。我不能使用 FormAcceptButton。我正在使用后续的 TabIndexes 遍历多个文本框。我必须使该按钮不可见并将方法附加到它 - 这不是太专业......

标签: c# .net winforms


【解决方案1】:

在处理程序中将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 中不起作用。

【讨论】:

    【解决方案2】:

    “叮”的声音来自未处理的表单事件。在您的表格上: 1.添加一个按钮,将其Visible属性设置为false 2. 将OnClick 事件处理程序添加到该按钮。保持方法为空 3. 将Form 的AcceptButton 属性设置为新按钮。 而已。 “叮”没了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 2011-04-14
      相关资源
      最近更新 更多