16. June 2005 15:48
by skills0
0 Comments
This wasn't immediately obvious to me and I did look through the docs a
bit without any luck. I had a group of images all embedded in the
same .resx file and I wanted to reference them programatically at
runtime. Typically if you have a single file embedded in your
project, you can just use the GetManifestResourceStream method off the
executing assembly and get a stream reference to the file. But
that doesn't work if you have multiple resources in the same resource
file, you can only get a handle to the main .resx file. The trick
is to use the ResourceManager class to reference the .resx file and
then you can get access to all the objects. So something like
this works:
System.Resources.ResourceManager
resourceManager = new System.Resources.ResourceManager("MyApplication.Images",
GetType().Assembly);
Image myImage = (Image)resourceManager.GetObject(imageName);