none
Where are the icons in ComponentResourceManager? RRS feed

  • Question

  • When I use the Insert Standard Items on a MenuStrip, statements like the below are added automatically:

    this.openToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("openToolStripMenuItem.Image")));

    The above statement inserts the File Open icon to the menu item.  Q1: May I know where are these icon images actually located?  Q2: And what other images are available?  The object resources is declared as:

    System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));

    If I use the Set Image... option (when I right-click a menu item in the Forms designer) a Select Resource dialog box opens up.  Q3: From this dialog box, how do I access the images in the resources object?

    Thanks
    • Edited by K.Kong Monday, November 24, 2008 2:47 AM Correction
    Monday, November 24, 2008 2:32 AM

Answers

  • They are stored in the form's .resx file.  Copied there by the MenuStrip designer from resources embedded in System.Windows.Forms.dll.  You can see their names by running Ildasm.exe on the reference assembly in c:\windows\ microsoft.net\ framework\ v2.0.50727.  Most of these can be loaded with the Bitmap(Type, String) constructor:

          Bitmap copyBmp = new Bitmap(typeof(Form), "copy.bmp");

    Whether you can legally use these bitmaps in your own program is murky.  Obviously, the ones produced by designer verbs are okay.


    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, November 28, 2008 1:13 PM
    Monday, November 24, 2008 11:42 AM
    Moderator

All replies

  • Hello K.Kong,

    Basically the standard icons / images are stored in frame work assemblies as embedded resources which automatically get linked with your application. The details are explained in this article
    http://msdn.microsoft.com/en-us/magazine/cc163609.aspx

    The following thread talks about consuming images from external dll

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/9247b912-5101-46c0-9af2-cd4b931f510e/

    Then answering your third question, the following article says how to use select resource dialog box

    http://msdn.microsoft.com/en-us/library/9928ad3f.aspx

    Regards


    SVK
    Monday, November 24, 2008 6:57 AM
  • SVK, thank you very much for putting together all the references.  Yes, I have worked with resource files before.  My questions were related to the specific situation of the Windows form.  Where are the resources hidden (Q1)?  I looked at Form1.resx but they were not there.  I am curious what else are available (Q2)?

    Thanks.
    Monday, November 24, 2008 10:46 AM
  • They are stored in the form's .resx file.  Copied there by the MenuStrip designer from resources embedded in System.Windows.Forms.dll.  You can see their names by running Ildasm.exe on the reference assembly in c:\windows\ microsoft.net\ framework\ v2.0.50727.  Most of these can be loaded with the Bitmap(Type, String) constructor:

          Bitmap copyBmp = new Bitmap(typeof(Form), "copy.bmp");

    Whether you can legally use these bitmaps in your own program is murky.  Obviously, the ones produced by designer verbs are okay.


    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, November 28, 2008 1:13 PM
    Monday, November 24, 2008 11:42 AM
    Moderator