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

Last updated by Tylah Kapa [SSW] about 1 year 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


Adam Cogan
We open source.Loving SSW Rules? Star us on GitHub. Star
Stand by... we're migrating this site to TinaCMS