Reputation: 857
In my WinForms app, if I set an icon for my app and an icon for my Form, the icon appears twice in my executable. Is it possible to avoid this?
(This question has been asked before, here, but the answers didn't seem to solve the problem. vanmelle's answer appears to extract only one icon (e.g., 16x16), Sunlight's answer extracts only the 32x32, and lc's answer doesn't solve the problem: there is still a duplicated icon in the executable.)
If it's not possible to accomplish this task, why is this? What is it about using the same icon for an executable and a Form that's so hard in WinForms?
Upvotes: 0
Views: 783
Reputation: 941545
This is an inevitable consequence of running managed code on a completely unmanaged operating system. Windows Explorer only knows how to read unmanaged resources. You can see what they look like, use File + Open + File in Visual Studio and select your .exe. You'll typically see three resource groups listed there:
This unmanaged resource data is separate from the managed resources you added. Managed resources are compiled into the assembly manifest. Unmanaged resources are stored in the .rsrc section of the image file. You can override the auto-generated version with the /win32res command line option. Which requires a .res file, a binary file that is generated from a .rc resource script by the rc.exe resource compiler. An age old Windows SDK tool.
This may change some day, the super-secret Midori project is a rumored to focus on a managed operating system. For now, we'll have to make do with the glue.
Upvotes: 5