How do I add a file to a exe

后端 未结 4 1266
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-25 12:04

I have a program that plays a sound but if I run it on a different computer it says that the file isn\'t found how do I attach the file onto the exe so when someone plays the ex

4条回答
  •  走了就别回头了
    2021-01-25 12:04

    If you are wanting to embed your wave file into your program, go to your Project Properties --> Resources --> Select Audio as the type then select Add Resource and select your Audio File. This will add the Audio File to your Resources Directory. Once you have done this you can right click on the File in the Resources folder and select Properties and change the Build Action to Embedded Resource.

    To access the file you would do something like this:

    System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.tada);
    sp.Play();
    

    enter image description here

    enter image description here

    enter image description here

提交回复
热议问题