Understanding Icon Indicies in a C# Application
I have a C# application that needs to define an icon for the project files that the user can save and load when using the application. I know how to set up the registry entries but what I am struggling with is the icon index for the DefaultIcon for the project file extension.
I've added the icon to the Resources file. I've also added the icon to the Resources folder in Visual Studio. Yet when I reboot my PC an index of one has no icon and an index of zero is the application icon.
I tried setting the icon persistence to "Embedded in .resx". Didn't help.
开发者_Go百科I added a new resource file called PublicIcons.resx, set the access modifier to "Public" and added the icon. Didn't help either.
I tried adding the icon directly to the project and setting the build action to "Embedded Resource". Again, didn't help.
Gaaaa! Why is such a simple task so annoying?
How do I add an icon to a C# project in Visual Studio and then discover the index of that icon so it can be used for a file type?
thanks, Andy
I've solved it. I have spent hours today trying to accomplish this simple task - reading about Setup and Deployment projects, ClickOnce, manifest files, fileAssociation tags, Visual Studio 2010 resource files, on and on and on. But here is how to solve the problem in literally two minutes:
In your VS2010 solution add a new empty C++ project: Add -> New Project -> Visual C++ -> Empty Project. I called my "ResourceLibrary".
Right click on the Resource Files folder then choose Add -> Resource... and select the icon.
Right click on the Source Files folder then choose Add -> New Item... -> C++ File. I called my main.cpp. Enter:
int main(void) { return 0; }
Then compile and associate your file with icon index zero in ResourceLibrary.exe using the appropriate registry entry and the installer program of your choice!
Simple and effective.
精彩评论