如何使用资源文件夹相对路径在C#窗口窗体应用程序? [英] How to use relative path to Resources folder in C# Window Form application?

查看:140
本文介绍了如何使用资源文件夹相对路径在C#窗口窗体应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想播放声音,当窗口形式加载,

I want to play sound when the window form loaded,

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

在发布这个项目给其他人,我不能使用绝对路径。那么,如何可以使用相对路径在这种情况下?其中, Song.mp3的位于C:\Users\xxx\Desktop\Game\Resources\song.mp3

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\song.mp3"?

谢谢,

推荐答案

创建资源捆绑并将其存储在捆绑,只是引用捆绑包中的声音文件

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

IE:默认情况下,创建一个WinForms项目时,你会看到在属性文件夹中的文件Resources.resx。添加有资源,然后从代码中引用:

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;

这篇关于如何使用资源文件夹相对路径在C#窗口窗体应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆