PC Review


Reply
Thread Tools Rate Thread

Add image to Context Menu Strip Menu Item in code

 
 
Joe Cool
Guest
Posts: n/a
 
      29th Jul 2009
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.
 
Reply With Quote
 
 
 
 
Jeff Johnson
Guest
Posts: n/a
 
      29th Jul 2009
"Joe Cool" <(E-Mail Removed)> 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 should be
using <projectName>.<resourceName> in the first place? Have you done this
sort of thing before?


 
Reply With Quote
 
 
 
 
Joe Cool
Guest
Posts: n/a
 
      29th Jul 2009
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
build context menu from menu strip parez Microsoft C# .NET 2 2nd Jun 2008 05:49 PM
build context menu from menu strip parez Microsoft Dot NET Framework Forms 0 2nd Jun 2008 04:35 PM
Extending the Menu strip in .NET 2.0 to display text on a status strip label Brian Henry Microsoft VB .NET 0 10th Nov 2005 10:03 PM
Custom Context Menu Strip msnews.microsoft.com Microsoft Dot NET Framework Forms 1 25th Jul 2004 05:56 PM
Re: Contect Menu Editor (Context Menu Editor / Context Menu Manager) BillR Freeware 5 13th Aug 2003 04:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:11 PM.