【问题标题】:Why does my WinForms application make a sound when "Enter" is pressed? [duplicate]为什么按下“Enter”时我的 WinForms 应用程序会发出声音? [复制]
【发布时间】:2018-10-22 22:33:26
【问题描述】:

我正在开发一个想要在视觉上模仿终端界面的 WinForms 应用程序。目标是让用户能够输入命令,例如 Zork

我在 KeyDown 上有一个带有事件处理程序的文本框,用于检查按下的键是否为 Enter,这部分工作正常。但是,每当我按“Enter”时,Windows(操作系统)都会发出音频 ping。没有其他按键会导致这种声音,所以我认为它与“Enter”按钮有关。

这里发生了什么?按“Enter”是我正在开发的外观和感觉中不可或缺的一部分!

【问题讨论】:

    标签: c# .net winforms


    【解决方案1】:

    您会看到某些键对操作系统来说是特殊的,因此它们会为它们添加特殊效果,要消除它们,您只需覆盖它即可。

    一种方法是

    if (e.KeyChar == 13)
    {
        // This one here tells the "operation system" that the event was handled 
        // and that it needs no further handling, therefor no 'Ding'
        e.Handled = true;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      • 2021-09-24
      • 2015-05-17
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多