在 C# winform 中,如何在 exe 文件中附加资源(例如图像)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11550441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
in C# winform, how to attach a resource (an image for example) with the exe file?
提问by vexe
I don't know if I asked it right, but basically what happened is that I made a winform app which loads its image from the resource folder .. the problem is that when i build the project and get the exe and give it to a friend, he won't have that resource folder like i do, so he'll get an error saying missing file.
我不知道我问的对不对,但基本上发生的事情是我制作了一个从资源文件夹加载其图像的 winform 应用程序..问题是当我构建项目并获取 exe 并将其提供给朋友,他不会像我一样拥有那个资源文件夹,所以他会收到一条错误消息,说缺少文件。
How can I somehow mix, or combine, or attach the image with my app?
我如何以某种方式将图像与我的应用程序混合、组合或附加?
采纳答案by Glenn Ferrie


You need to add it to the project by navigating to the Properties Window and going to the resource tab and adding the image from there.
您需要通过导航到“属性”窗口并转到资源选项卡并从那里添加图像来将其添加到项目中。
Alternatively, from the PictureBox Control you can import resource from your computer.
或者,您可以从 PictureBox 控件导入计算机中的资源。


回答by Riccardo
if you don't need to update it in the future, compile your program with the image property build action set to embedded resource. if you need to change it in the future compile with property build action set to content.
如果您以后不需要更新它,请使用设置为嵌入资源的图像属性构建操作来编译您的程序。如果您以后需要更改它,请将属性构建操作设置为内容进行编译。

