如何访问在C#项目中嵌入的资源? [英] How can I access embedded resources in a C# project?

查看:223
本文介绍了如何访问在C#项目中嵌入的资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数你只需要访问他们像这样我已经知道了这个问题的答案线程:

Most of the threads I've read about this question answer that you just have to access them like this:

<MyProjectNamespace>.Properties.Resources.<MyResourceName>

但在构建过程中,我有这样的消息:

But at the build process I have this message:

<MyProjectNamespace> does not contain a definition for 'Properties'

看来,类属性通常是自动生成的IDE,当您将资源添加到您的项目。

It seems that the class 'Properties' is normally auto-generated by the IDE when you add resources to your project.

事实是,我工作的Eclipse和我真的不知道如何添加资源,但我设法生成从Visual Studio(我用它来设计我的Windows窗体)一个.resx文件,我添加到南特.build文件作为资源,伴随着我的位图。然后,它的确是嵌入的资源,但我不能访问他们...

The fact is that I'm working on Eclipse and I don't really know how to add resources, but I managed to generate a .resx file from Visual Studio (which I use to design my Windows form) that I added to Nant .build file as a 'resource', along with my bitmaps. Then it indeed embed the resources, but I can't access them...

所以,我怎么能嵌入资源,在我的应用程序(通常),并访问他们,使用Eclipse + Emonic +南特建造的呢?

So how can I embed resources in my application (normally), and access them, using Eclipse + Emonic + Nant to build it?

谢谢

保罗。

推荐答案

您应该创建一个的ResourceManager 实例打开RESX文件是这样的:

You should create a ResourceManager instance to open a resx file like this:

ResourceManager resources = new ResourceManager("<MyProjectNamespace>.Properties.Resources", typeof(<any type in the assembly>).Assembly);
string myString = resources.GetString("myString");
Bitmap myBitmap = resources.GetObject("myBitmap") as Bitmap;

如果他们是一种形式的资源,你也可以让他们如下:

If they are the resources of a form you can also get them as following:

ResourceManager resources = new ResourceManager(typeof(Form1));

这篇关于如何访问在C#项目中嵌入的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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