hadi
hadi

Reputation: 137

play windows 7 sound effect in C#

hi I want to play a windows 7 sound effect when a user clicks a button in my Windows windows application in XP using C#

thanks

Upvotes: 0

Views: 1946

Answers (2)

anishMarokey
anishMarokey

Reputation: 11397

In button click you can call this

 using System.Media;
 Protected void ButtonClick(object sender, EventArgs e)
 {
 SoundPlayer simpleSound = new SoundPlayer(@"c:\Windows\Media\Windows7.wav");
    simpleSound.Play();
 }

Note: If you are looking for .wav for windows. normally it is present in the folder

C:\Windows\Media...

Upvotes: 2

p.campbell
p.campbell

Reputation: 100557

You can use the .NET Framework class System.Media.SystemSounds.

From the C# FAQ:

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

For the Windows 7 and XP issue, you'd have to import the .wav files from 7 into XP, and associate those .wav to the appropriate events.

Alternatively, you could embed any .wav file into your application as a resource, and play it from your app. Likely easiest is the SoundPlayer class.

Upvotes: 3

Related Questions