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'
It seems that the class 'Properties' is normally auto-generated by the IDE when you add resources to your project.
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...
So how can I embed resources in my application (normally), and access them, using Eclipse + Emonic + Nant to build it?
Thanks,
Paul.
Embedded files are called as Embedded Resources and these files can be accessed at runtime using the Assembly class of the System. Reflection namespace. Any file within the project can be made into an embedded file.
Open Solution Explorer add files you want to embed. Right click on the files then click on Properties . In Properties window and change Build Action to Embedded Resource . After that you should write the embedded resources to file in order to be able to run it.
A manifest resource is a resource (such as an image file) that is embedded in the assembly at compile time. For more information about manifest resources, see Microsoft .
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With