如何在KeyDown事件上禁用蜂鸣声 [英] How Do I Disable the Beep Sound on KeyDown Events

查看:117
本文介绍了如何在KeyDown事件上禁用蜂鸣声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面列出了我的KeyDown事件代码的一部分。用户按Ctrl + Y可以执行KeyDown事件。但是,完成此操作后,会发出一声我要禁用的哔声。我还将表单的KeyPreview属性设置为True。



我认为e.SuppressKeyPress = True语句会禁用蜂鸣声,但事实并非如此。



当用户按下Ctrl + Y键时,我需要什么声明才能停止发出哔哔声?



I have listed a portion of my KeyDown event code below. The KeyDown event can be executed by the user pressing Ctrl+Y. However, when this is done, there is a beep sound that I want to disable. I have also set the KeyPreview property of the form to True.

I thought the e.SuppressKeyPress = True statement would disable the beep, but it does not.

What statement do I need in order to stop the beep sound when the user presses the Ctrl+Y keys?

Private Sub frmAddEditAssets_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
           Case (Keys.Control + Keys.Y)
               e.SuppressKeyPress = True
               Call YearEndUpdate()
       End Select

推荐答案

替换 e.SuppressKeyPress = true; e.Handled = true;
Replace the e.SuppressKeyPress = true; with e.Handled = true;


嗨Dave,



感谢您的及时回复。但是,由于某种原因,即使将语句更改为e.Handled = true(来自e.SuppressKeyPress = True),在执行KeyDown事件时仍会发出蜂鸣声。



更新:后来我意识到发出蜂鸣声的原因是因为MessageBox.Show命令。蜂鸣声与MessageBox相关联,而不是与KeyDown事件相关联。我发现如果我按如下方式设置MessageBox图标: MessageBoxIcon.Question ,则没有蜂鸣声。所有其他MessageBox图标都有一个与之关联的哔声。
Hi Dave,

Thank you for your prompt response. However, for some reason, even after changing the statement to e.Handled = true (from e.SuppressKeyPress = True), there is still a beep sound when the KeyDown event is executed.

Update: I realized later that the reason for the beep was because of the MessageBox.Show command. The beep was associated with the MessageBox, not the KeyDown event. I found that if I set the MessageBox icon as follows: MessageBoxIcon.Question, then there is no beep. All of the other MessageBox icons have a beep sound associated with them.


这篇关于如何在KeyDown事件上禁用蜂鸣声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆