How can I access the embedded resources in a C # project?

Most of the threads I read about this question answer that you just need to access them as follows:

<MyProjectNamespace>.Properties.Resources.<MyResourceName> 

But during the build process, I have this message:

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

It seems that the Properties class is usually autogenerated by the IDE when adding resources to your project.

The thing is, I'm working on Eclipse and I really don't know how to add resources, but I managed to create a .resx file from Visual Studio (which I use to create my Windows form), which I added to the Nant.build file as "resource" along with my bitmap images. Then it really inserts the resources, but I cannot access them ...

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

Thanks,

Paul.

+6
source share
2 answers

You need to create an instance of ResourceManager to open the resx file as follows:

 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 form resources, you can also get them as:

 ResourceManager resources = new ResourceManager(typeof(Form1)); 
+3
source

Try using the ResourceManager in the System.Resources namespace. Obviously, this depends a little on what you are trying to extract, but mine looks like this:

 ResourceManager.GetString("String1", resourceCulture); 
0
source

Source: https://habr.com/ru/post/889983/


All Articles