0

I have a picturebox that I want to load an image into at runtime depending on what a user types in a textbox.

I have created a file named Formations.resx within my project and loaded my images into it. I am have tried both of the following but had no luck, what am I doing wrong?

pictureBoxFormation.Image = Properties.Resources.ResourceManager.GetObject("random_" + firstPoint) as Image;

This code executes fine, but the .Image property of my picturebox isn't updated by it, I am guessing that this code doesn't look in my file specifically, where is it looking?

ResourceManager rm = new ResourceManager("Formations", Assembly.GetExecutingAssembly());
pictureBoxFormation.Image = rm.GetObject("random_" + firstPoint) as Image;

This throws an error, which is as follows:

An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Formations.resources" was correctly embedded or linked into assembly "WindowsFormsApplication1" at compile time, or that all the satellite assemblies required are loadable and fully signed.

blawford
  • 435
  • 5
  • 18
  • Your title and post do not match. Please change one of them so the title matches your question. – nvoigt Aug 27 '14 at 07:14
  • Oh and yes, please post the error, the crystal ball I ordered has not yet arrived. – nvoigt Aug 27 '14 at 07:15
  • Done and done. When I logged in I had an old question I got half way through asking before I solved it waiting for me, I deleted the contents but not the title. – blawford Aug 27 '14 at 08:26
  • 1
    The first snippet doesn't work because you didn't add the images to the Properties/Resources.resx file. The second doesn't work because you got the resource stream name wrong. It is prefixed by the project's default namespace name. So "WindowsFormsApplication1.Formations" ought to be the correct name. If you're thinking about picking a better project name, you should, then do so now. – Hans Passant Aug 27 '14 at 08:54
  • Moved the resources to Properties/Resources and it worked. I did try adding the namespace to the second way of doing things before asking my question, but to no avail. I have also renamed the project to something more suitable. If you add your comments as an answer I will happily accept, thank you. – blawford Aug 27 '14 at 09:30

1 Answers1

1

Ended up moving the resources to Properties/Resources as suggested by Hans Passant, described in the comments to the original post.

blawford
  • 435
  • 5
  • 18