.NET Zone is brought to you in partnership with:

Senthil Kumar is a Software Engineer who has around 3 years of experience in IT industry. He is currently working as a Software Engineer in Bangalore and works mainly on the Windows or Client Development technologies and has good working experience in C#/.NET, Delphi, Winforms and SQL Server. He is also a Microsoft Technology Certified Professional in ASP.NET. He Blogs at http://www.ginktage.com and http://www.windowsphonerocks.com. He enjoys learning as much as he can about all things related to technologies to get a well-rounded exposure of technologies that surround him. Senthil completed his Master of Computer Applications from Christ College (Autonomous), Bangalore in the year 2009 and is a MCA Rank Holder. He has passion for Microsoft technologies especially Windows Phone development. You can connect with him on Twitter at (http://twitter.com/isenthil) , on Facebook at (http://www.facebook.com/kumarbsenthil) and his blog (www.ginktage.com). Senthil is a DZone MVB and is not an employee of DZone and has posted 118 posts at DZone. You can read more from them at their website. View Full User Profile

How to Play Default Windows Sounds in your .NET Application

08.20.2012
| 1804 views |
  • submit to reddit

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

 

Published at DZone with permission of Senthil Kumar, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)