Retrieving resource image files that are embedded in a custom control

J

Joanne

Hi,

I have a custom control that has a folder (resources) of embedded bmp
images. I use the public method (ImageName) below to tell the control the
string name of the embedded image that I want the control to display. The
method should assign a new bitmap image from the custom controls embedded
image to my private Image field using the GetManifestResourceStream method.

I'm setting imageName to namespace.resourcesfolder.filename.bmp like
"NS_TitleBar.resources.trainingpic1.bmp" but I keep getting an error from
the *forms designer* that says the image cannot be set to null. so it looks
like the main line of code below cannot find the embedded resource image.

Any ideas?

public string ImageName
{
get
{
return this.imageName;
}
set
{
this.imageName = value;
this.image = new
System.Drawing.Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(imageName));
this.Invalidate();
}
}
 
A

Alex Feinman [MVP]

Are you sure you are not getting from designer error *before* the code below
had a chance to execute?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top