Over a million developers have joined DZone.

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 .

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);

 

Topics:

Published at DZone with permission of Senthil Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}