KansaiRobot
KansaiRobot

Reputation: 9912

How to create resx files

I am trying to use Icons in a windows form application. I read that you can use resx files to do this. (I also read that resx files can be used for localization but this is not the point of this question)

I know more or less how to use a resx file if I have one(see below). What I don't know and I can't find anywhere is how to create these resx files (I know what these files are already)

Can someone teach me how to create a resx file that holds information on icons non-programmatically (the few responses about this in SO are programmatical ones)

The objective is to have a "resource.resx" file in my project that holds data about a "myicon.ico" file.


I am planning to use this as in

ResourceManager rm = new ResourceManager("resource", 
                           typeof(Resource).Assembly);
Object ret= rm.GetObject("something");
if(ret!=null && ret is Icon)
  return (Icon)ret;
else
  return null;

Please don't point me to this link since I have already read it and could not find a practical way to do what I asked.

Upvotes: 7

Views: 18555

Answers (1)

ProgrammingLlama
ProgrammingLlama

Reputation: 38767

Assuming you're using Visual Studio:

  1. Right-click your project
  2. Select Add | New Item
  3. Select Resources File
  4. Give it a name (e.g. Resources)
  5. Click Add
  6. You will now have a Resources file in your project with the name you provided, and it should auto-open the resources editor. If it doesn't, double-click it in the project.
  7. In the top-left of the editor, click the "Strings v" drop down and select "Icons".
  8. Drag your icon into this screen.
  9. Rename it to whatever you want (e.g. something).

If you named your resources file "Resources", you should be able to access the icon like so:

Object ret = Resources.ResourceManager.GetObject("something");
if (ret != null && ret is Icon)
    return (Icon)ret;
else
    return null;

Upvotes: 14

Related Questions