On Jul 28, 8:29*pm, "Jeff Johnson" <i....@enough.spam> wrote:
> "Joe Cool" <joecool1...@live.com> wrote in message
>
> news:0666f162-dda1-4bea-a4c5-(E-Mail Removed)...
>
>
>
>
>
> >I am trying to add a project resource image to a contextmenustrip
> > menuitem in code. Here is the code:
>
> > * * * * * *ContextMenuStrip cm = new ContextMenuStrip();
> > * * * * * *Image image;
> > * * * * * *Stream s;
>
> > * * * * * *s = this.GetType().Assembly.GetManifestResourceStream
> > ("myProjectName.resourcepicturename");
> > * * * * * *image = Image.FromStream(s);
> > * * * * * *cm.Items.Add(new ToolStripMenuItem("Menu Item Text",
> > image, this.MenuItemHandler_Click));
>
> > It dies trying to assign the image from the stream to the Image
> > variable. Error is:
>
> > Value of 'null' is not valid for 'stream'.
>
> > Any help appreciated.
>
> Are you sure you have the case correct in
> "myProjectName.resourcepicturename"? And how did you determine you shouldbe
> using <projectName>.<resourceName> in the first place? Have you done this
> sort of thing before?
I found this page:
http://support.microsoft.com/kb/324567
But it doesn't spefically describe what I want to do. The image
property for a ContextMenuStrip ToolStripMenuItem is an Image
datatype. The resource image was loaded from a JPG file. I gathered
from that webpage, the resource name was case-sensitive.
Knowing that an Image datatype variable can be loaded with the
Image.FromStream method, I decided to try this approach, but I don't
know what I am doing wrong.