5
votes

My company has a branding mechanism that sets the icon for a Windows Application, like so:

if (AppBranding.Is("FOO"))
    Icon = MyProject.Properties.Resources.Icon_FOO;
else
    Icon = MyProject.Properties.Resources.Icon_BAR;

Icon_FOO and Icon_BAR are resources that point to their respective .ico files.

Also, Icon and manifest in Project > MyProject Properties > Resources is set in Visual Studio.

enter image description here

When users launch the application, the correct icon appears based on branding. However, if they pin the program to the taskbar, the icon reverts to Icon_FOO.ico, regardless of branding. When they unpin it, the icon toggles back.

I believe that programs pinned to the taskbar use the icon of the .exe, while the icon for the Window is whatever I set Form.Icon to be. I only know how to set the .exe icon by going to Project Properties > Resources and making a selection from the drop down list, as I have in the picture above. How can the icon for the .exe be set dynamically?

1

1 Answers

1
votes

The icon in the taskbar is (usually) the first icon resource available in the assembly, and cannot be modified from within the application (unless you create a custom shortcut programmatically).

Instead of trying to manipulate this, you can create a simple starter application (*.exe) with the correct icon and version attributes for each branded version? The .exe than only needs to load the application from an assembly that contains the actual application content.

so you have

Launcher_FOO.exe
Launcher_BAR.exe

with their own custom icons. Both application will create a common application from

Actual_Application.dll

to start the application.

You may use Reflection.Emit to create the Launcher_xxx.exe on the fly:

see google search

see msdn