开发者

How to use relative path to Resources folder in C# Window Form application?

开发者 https://www.devze.com 2023-02-23 01:53 出处:网络
I want to play sound when the window form loaded, SoundPlayer sound = new SoundPlayer( @\"song.mp3\" );

I want to play sound when the window form loaded,

SoundPlayer sound = new SoundPlayer( @"song.mp3" );
sound.Play();

When distributing this project to others, I can't use absolute path. So how can I use relative path in this case? Where the song.mp3 is located in "C:\Users\xxx\Desktop\Game\Resources\son开发者_开发问答g.mp3"?

Thanks,


Create a resources bundle and store it in the bundle, and just reference the sound file within the bundle.

IE: when creating a winforms project by default, you'll see a Resources.resx file in the Properties folder. Add a resource there, and then reference it from code:

Properties.Resources.String1;
0

精彩评论

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