Friday, 10 May 2013

Play a sound on Click code

I've found two codes where you click an object and a sound will play:

System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"c:\mywavfile.wav"); < change this part to whatever sound we want
player.Play();



 
private void Button_Click(object sender, EventArgs e)
{
using (var soundPlayer = new SoundPlayer(@"c:\Windows\Media\chimes.wav")) {
soundPlayer.Play(); // can also use soundPlayer.PlaySync()
}
}


 

No comments:

Post a Comment