C# Frequently Asked Questions

The C# team posts answers to common questions

How do I play default Windows sounds?

Sometimes, you might want to make your application a bit more audible. If you are using .NET 2.0, you can utilize the new System.Media namespace and its SystemSound and SystemSounds classes.

The SystemSounds class contains five static properties that you can use to retrieve instances of the SystemSound class. This class in turn contains the Play() method, which you can use to play the wave file associated with the sound in Windows Control Panel. Note that the user can also disable all sounds altogether, which would mean that no sound can be heard through the computer speakers.

To play for example the classical beep sound, you could use the following code:

System.Media.SystemSounds.Beep.Play();

Similarly, you could play the “Question” sound with this code:

System.Media.SystemSounds.Question.Play();

The System.Media namespace is defined in System.dll, so there are no new DLLs you would need to add to your project’s references to use the above code.

[author: Jani Järvinen, C# MVP]

Published Monday, March 27, 2006 7:03 PM by CSharpFAQ
Filed under:

Comments

 

Matt Blodgett said:

Easy Notifications with System.Media.SystemSounds

October 22, 2007 3:07 PM
Anonymous comments are disabled

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker