C# Winforms change taskbar icon

633 views Asked by At

I have an old legacy system that uses Winforms and is published with the built in One click, I look after 3 different installs and each one has its own database it connects to, so its been set up that when a different system is click, it check isCompany1 and will set the Favicon accordingly so when depoyment is done in the application window the Icon and Manifest is set to the correct ICO, when installed the .exe icon will be what is set there,

However i am trying to bring these all inline as when we debug a drop asks which database we would like to connect to, and depending on that it will set things up differently. When running in VS the icons in the taskbar will change accoring to the dynamic Favicon however when its depolyed with this new selection it wont change, (it will change once on first load, then wont again)

The issue is some users need access to the different instances so would like different icons at the bottom, but its not changing the task menu, but everything else such as ALT-TAB and the control panel icon is changing,

all forms link into a baseform and call this :

if (App.IsCompany1)
{
    this.Icon = new Icon("Resources\\Company1.ico");
}
else if (App.Company2)
{
    this.Icon = new Icon("Resources\\Company2.ico");
}
else if (App.Company3)
{
    this.Icon = new Icon("Resources\\Company3.ico");
}

AS i said this will change everything but not the Taskbar, but will from VS debugging,

I have made sure the .ico has all sizes, by writing their sizes on each one, and they display correctly the Taskbar and ALT-TAB both use 32x32

1

There are 1 answers

5
Caius Jard On

If it's any consolation, I couldn't reproduce your complaint.

I put 3 icons in resources, a single button on a form, this code:

    private int iconum = 0;
    private Icon[] icons = new[] { Properties.Resources.icon1, Properties.Resources.icon2, Properties.Resources.icon3 };

    private void button1_Click(object sender, EventArgs e)
    {
        this.Icon = icons[iconum++ % icons.Length];
    }

And it cycled through the icons in the main form title bar and the windows task bar over and over on every button click (made sure to run a release built exe too, not a debug start):

enter image description here

Note: the thing in the top right is my taskbar