开发者

How to add audio file to my form?

开发者 https://www.devze.com 2023-02-16 10:52 出处:网络
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百科

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

精彩评论

暂无评论...
验证码 换一张
取 消