Tags

,

Add the file (or icon) to the project, I like to create a folder for all my resource files.

1. (optional) Right click on the project and selected “Add” and then “New Folder”.
2. (optional) Rename new “NewFolder” to “Resources”.
3. Right click on the project (or “Resources” folder) and selected “Add” and then “Add Existing Item”.
4. Find the file (or icon).
5. Right click on the newly added file and select “Properties”
6. Set the “Build Action” property to “Embedded Resource”

Now when you compile the executable the file (or icon) will be embedded.

To use the embedded file use the following code (I have written it like this to illustrate the different steps, clearly you can condense the code into fewer lines)

System.Drawing.Icon icnTask;
            System.IO.Stream st;
            System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
            st = a.GetManifestResourceStream("{{NameSpace}}.Resources.TaskIcon.ico");
            icnTask = new System.Drawing.Icon(st); 
Advertisements