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

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0577 – The Conditional attribute is not valid on ‘function’ because it is a constructor, destructor, operator,...
Are you using LINQ in C# and requite to remove all objects matching the condition from a List ? Read...