Hi,

my app creates some components at runtime such as a PictureBox.

Because they are only created at runtime I have no way of setting the ErrorImage through the properties section.

I thought I could just add the images I required to the programs resx file but found out that that is rewritten at compile time and clears out 'dirty' resources, like my manually added images.

OK, I thought, I'll just create my own resx file and add the images to that, which I did.

The issue I have now is how to actually call the images from the newly created resx file.

I found some code on the net but cannot get it to work:-

ResourceManager MIrm = new ResourceManager ("MyImages", Assembly.GetExecutingAssembly());

pb.ErrorImage = ((System.Drawing.Image)(MIrm.GetObject("pb.ErrorImage")));

my resx file is called MyImages.resx & I have an image in it called pb.ErrorImage.

When using the above code I receive an error:-

System.Resources.MissingManifestResourceException: could not find any resources appropriate for the specified culture...... etc.

Also, I cannot really seem to find out exactly where my resx file is supposed to be in the Project tree, at the moment it is located inside of the Properties folder.


Any help would be appreciated.

Kind regards..,

MT ;)

Recommended Answers

All 5 Replies

Did you try adding the resources using the Resources tab of the project properties.

If you want to use your current resource file then you need to refer to it using the project namespace.

Since your resx file is located in the Properties folder then this will be:

ResourceManager MIrm = new ResourceManager ("MyProject.Properties.MyImages", Assembly.GetExecutingAssembly());

Did you try adding the resources using the Resources tab of the project properties.

That is one piece of information that I have seen in various places on the web, although I am using SharpDevelop and can't for the life of me see a Resource tab within the Projects Properties.

Regards..,

p.s. As a workaround for the time being I have placed a really small and hidden PictureBox on my form and added the image to that, which has imported it into the main resx file and I can use it from there on my dynamically created PictureBox.
Not a perfect solution but it works for now.

MT ;)

If you want to use your current resource file then you need to refer to it using the project namespace.

Since your resx file is located in the Properties folder then this will be:

ResourceManager MIrm = new ResourceManager ("MyProject.Properties.MyImages", Assembly.GetExecutingAssembly());

OK, thanks. I will try that out.

Regards..,

MT ;)

Thanks, all sorted now with your help.

Regards..,

MT :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.