I want to add an audio file to my form so that when any button event occurs, if anything is clicked then the audio file will play.
开发者_JAVA百科How can I do this?
code for adding audio?
private void playSoundFromResource(){
SoundPlayer sndPing = new SoundPlayer(SoundRes.GetType(), "Ping.wav");
sndPing.Play();
}
Well, a much more better way to write your code is to put the following code in form1.cs
private void Form1_Load(object sender, EventArgs e)
{
SoundPlayer Mcd = new SoundPlayer(@"C:\Users\Mcd\Desktop\abcd.wav");
Mcd.PlayLooping();
}
精彩评论