Sound - Did you know that a message box automatically plays a beep?

Last updated by Tylah Kapa [SSW] 4 months ago.See history

A message box automatically provides this functionality so there is no need to manually put a beep right before a message box pops up.

Win7SoundError
Figure: Good example - Windows message boxes plays a sound... which cannot be captured in screenshot form.

string message = "You did not enter a server name. Cancel this operation?";
string caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
System.Media.SystemSounds.Beep.Play();
DialogResult result = MessageBox.Show(this, message, caption, buttons);

Figure: Bad example - The sound on the button is hardcoded in this code snippet

string message = "You did not enter a server name. Cancel this operation?";
string caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result = MessageBox.Show(this, message, caption, buttons);

Figure: Good example - The code is not present in this example as it is automatically done

We open source. Powered by GitHub