I have a controls library which I've added a .resx file to (ImageResources.resx). It contains two .png images which I subsequently added.
In that same library I have a control which loads a couple of images to do some custom drawing, but I don't seem to be able to load the resources:
void GTableLayoutPanel::SetBorderImagesFromManifest(String^ topLeftCornerImageName, String^ topImageName)
{
// Grab the assembly this is being called from
Assembly^ assembly = Assembly::GetExecutingAssembly();
// Grab the images from the assembly
Stream^ stream = assembly->GetManifestResourceStream(topLeftCornerImageName);
Image^ topLeftImage = System::Drawing::Image::FromStream(stream);
stream = assembly->GetManifestResourceStream(topImageName);
Image^ topImage = System::Drawing::Image::FromStream(stream);
// Update the internal store from the supplied images
SetBorderImages(topLeftImage, topImage);
}
...gives me errors complaining that stream
is null which suggests my call to GetManifestResourceStream
is failing.
The images are called group_box_top.png
and group_box_top_left.png
and I'm calling the image loader as follows:
SetBorderImagesFromManifest("group_box_top_left.png", "group_box_top.png");
I've also tried:
SetBorderImagesFromManifest("group_box_top_left", "group_box_top");
...because the files appear in the .resx file without the .png extensions, but this gives the same error.
Have I missed a step here?
[Edit] I tried the suggestion in that final link and I get:
MyControlsLib.ImageResources.resources
So now I've tried referencing:
Stream^ strm1 = assembly->GetManifestResourceStream("MyControlsLib.ImageResources.resources.group_box_top_left");
Stream^ strm2 = assembly->GetManifestResourceStream("MyControlsLib.ImageResources.resources.group_box_top_left.png");
Stream^ strm3 = assembly->GetManifestResourceStream("MyControlsLib.ImageResources.group_box_top_left");
Stream^ strm4 = assembly->GetManifestResourceStream("MyControlsLib.ImageResources.group_box_top_left.png");
...all of which return nullptr :-/