tags:

views:

80

answers:

3

hi i have made an window based application using C# .Net and i want to play a specific sound when i click on Button so what should i do?

does it require any dll for that..

please inform me precisely

+10  A: 

For Windows Forms one way is to use the SoundPlayer

private void Button_Click(object sender, EventArgs e)
{
    SoundPlayer simpleSound = new SoundPlayer(@"c:\Windows\Media\chimes.wav");
    simpleSound.Play();
}

MSDN page

This will also work with WPF, but you have other options like using MediaPlayer MSDN page

ChrisF
Should probably be wrapped in a `using` statement as it inherits from `Component`
ck
@ck - I was just showing the basics, but yes in production code wrap it up in a `using`.
ChrisF
+3  A: 

You could use:

System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"c:\mywavfile.wav");
player.Play();
bporter
This is perfect answer because a new user can understand that SoundPlayer belongs to System.Media....
+2  A: 

You can use SystemSound

e.g. SystemSounds.Asterisk.Play();

RandomNoob
+1 cool, I didnt know that
Akash Kava