How to Play Default Windows Sounds in your .NET Application
There are times when you want your Application to play default Windows Sounds when an alert message is displayed .
If you want to play different sounds defined in the Sounds and Alerts section of the control panel in your .NET Application , you can utilize the System.Media.SystemSounds class that is defined in the System.Media namespace.
This class contains 5 properties (static) which can be used to retreive the instances of the SystemSound .
Each of these also contain the Play method which is used to play the sound defined in the Windows Control Panel .
If you want to play the sound all that you can do is call the play method as shown below
System.Media.SystemSounds.Asterisk.Play(); System.Media.SystemSounds.Beep.Play(); System.Media.SystemSounds.Exclamation.Play(); System.Media.SystemSounds.Hand.Play(); System.Media.SystemSounds.Question.Play();
Incase , you use the MessageBoxIcon as one of the options while displaying the MessageBox , you will right sound based on the selected Icon too .
MessageBox.Show("test", "success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)