Play default Windows sounds

Jump to: navigation, search

These C# code snippets—in .NET 2.0 and later versions—use the System.Media namespace—SystemSound and SystemSounds classes—to play the default Windows sounds.

The SystemSounds class contains five static properties that can be used to retrieve instances of the SystemSound class.

The SystemSound class contains the Play() method, which can be used to play the wave file (.wav) associated with a particular sound in the Windows Control Panel.

To play the classical beep sound, use the following code:

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

Alternatively, play the "Question" sound with the following code:

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

The System.Media namespace is defined in System.dll. So, no new DLLs need be add to the project references in order to use these examples.

Remember: the user may disable all sounds, so the computer speakers will generate no sound.

SystemSounds Properties:

Name Description
Asterisk Gets the sound associated with the Asterisk program event in the current Windows sound scheme.
Beep Gets the sound associated with the Beep program event in the current Windows sound scheme.
Exclamation Gets the sound associated with the Exclamation program event in the current Windows sound scheme.
Hand Gets the sound associated with the Hand program event in the current Windows sound scheme.
Question Gets the sound associated with the Question program event in the current Windows sound scheme.
C# Online.NET