资源,放置它们的位置以及如何在C#中引用它们 [英] Resources, where to put them, and how to reference them in C#

查看:68
本文介绍了资源,放置它们的位置以及如何在C#中引用它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用C#和其他编程语言一段时间了,很and愧地说我不熟悉将资源(例如程序图标)放置在哪里以及如何在代码中引用它们的标准。

I've worked with C# and other programming languages for a while now, and am ashamed to say I'm unfamiliar with the standard on where to put resources such as program icons, and how to reference them within my code.

具体来说,对于C#Windows Forms应用程序,将图标资源放在哪里合适?一旦将它们放在正确的位置,引用它们的路径是什么? ?

Specifically, for a C# Windows Forms Application, where would it be appropriate to put my icon resources, and what is the path for referencing them once I get them in the correct place?

非常感谢您的协助。

推荐答案

您可以在您的项目中添加一个 Resources.resx 文件,并向其中添加资源,例如图像,字符串,文件。然后,您可以通过自动生成的资源类引用这些资源。默认情况下,Visual Studio将在属性目录中创建一个 Resources.resx 文件。默认情况下,您添加到资源文件中的所有资源都会添加到资源目录中。

You can add a Resources.resx file to your project and add resources like images, strings, files to it. Then you can reference these resources through an automatically-generated Resources class. By default, Visual Studio will create a Resources.resx file in the Properties directory. Any resources you add to the resources file will be added to the Resources directory by default.

例如

this.BackgroundImage = Properties.Resources.MyImage;

这篇关于资源,放置它们的位置以及如何在C#中引用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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