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 that is 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 .

These include

  • System.Media.SystemSounds.Asterisk
  • System.Media.SystemSounds.Beep
  • System.Media.SystemSounds.Exclamation
  • System.Media.SystemSounds.Hand
  • System.Media.SystemSounds.Question

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);
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


x

Interesting BlogPosts to read

Download - Pokemon Go for for Windows 10 (Third Party app)
Pokemon Go is one of the popular AR games for android and iOS devices and now , the game is made ava...
Open Wordpad from command line in Windows
You can use the command "Write" from command line in Windows to open the WordPad application.D:\>...
Popular cross-platform (android and iOS) to-do list app
In this blog post, we will cover some of the popular to-do list app that is available on different p...