Whenever trigger a messagebox used in my C# program I get a very annoying beep from my computer. How do I disable this beep using C# code.
The code I am using is very simple.
MessageBox.show("text");
Whenever trigger a messagebox used in my C# program I get a very annoying beep from my computer. How do I disable this beep using C# code.
The code I am using is very simple.
MessageBox.show("text");
This is going to sound weird until you have tried it. Open your command prompt, type:
net stop beep
I did a quick google and found 4 other ways:
From the searching I've done it looks like the beep is hardwired into the Win32 message box function:
So you need to either write your own method or stop the beep in the hardware. The former will work for everyone, the latter just for you.
Depending on how much you're leveraging the MessageBox (icons, etc) you can always make a custom dialog. Especially if it's a simple message you want to display, this would not be difficult or time consuming.
You should leave it to the end user to decide what sounds he wants. He can configure/disable sounds for system events such as a messagebox in Control Panel / Sounds and Audio Devices / Sounds / Program Events.
Stopping the beep service required administrative privileges, and isn't something you'd normally do just for one application.
If you do go for a custom dialog to replace the MessageBox, please remember to implement CTL-C (copy messagebox contents to clipboard).
Try using the VisualBasic MsgBox class instead of the MessageBox. I cannot explain why, but on my computer, the VisualBasic one doesn't beep.
http://msdn.microsoft.com/en-us/library/sfw6660x%28VS.85%29.aspx
So instead of:
MessageBox.Show("text")
do:
MsgBox("text")
You'll have to import the MsgBox function from Microsoft.VisualBasic, instead of importing MessageBox from System.Windows.Forms. But that shouldn't be a problem; it's part of the .NET api.
EDIT: Ah ok, now I can explain it. The lack of sound is because the VB version of the messagebox is undecroated (i.e. it's not informational, a question, etc.) by default. I assume there's no real need to use the VB MsgBox class after all--probably if you make the regular old MessageBox undecorated, it won't make any sound either. :)