Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a different taskbar icon to the icon displayed in the titlebar (C#)?

Tags:

I have both dark and light versions of my application icon; the dark version works best on gray surfaces such as Windows XP taskbar, where the light version works best as an icon in the titlebar.

Is there a way I can set the icon in the taskbar to a different icon than the one used in my form in C# (P/Invoke is fine)?

like image 440
Hach-Que Avatar asked Oct 29 '10 04:10

Hach-Que


People also ask

How do I make my taskbar icons different?

Alternatively, if you hold Shift and right-click the icon on the taskbar, you get the standard Windows Explorer context menu, instead of the application jump list. Again, click Properties. From the Properties dialog, go to the Shortcut tab and click the Change Icon button. Select a new icon file by clicking Browse.

How do I put different icons on the taskbar in Windows 10?

If you want to manage and customize the Taskbar icons, just right-click on the Taskbar, select Settings, then under Multiple displays, look for Combine buttons on the taskbars, and select Never on the drop-down menu. This will change the Taskbar icons to your preferred Taskbar view.

How do I make my taskbar icons show names?

Click on Start > Settings Personalization > Taskbar. Scroll down to Combine taskbar buttons. Click on Never. If you click on When taskbar is full, then application names will only appear as long as they fit into your taskbar.


2 Answers

Send the WM_SETICON message to your form with different icon handles for the ICON_SMALL and the ICON_BIG parameter:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);

private const uint WM_SETICON = 0x80u;
private const int ICON_SMALL = 0;
private const int ICON_BIG = 1;

public MyForm()
{
    InitializeComponent();

    SendMessage(this.Handle, WM_SETICON, ICON_SMALL, Properties.Resources.IconSmall.Handle);
    SendMessage(this.Handle, WM_SETICON, ICON_BIG, Properties.Resources.IconBig.Handle);
}
like image 145
Andreas Adler Avatar answered Nov 24 '22 12:11

Andreas Adler


I know this is an old question but I came across it when trying to achieve the same thing, and well yes you can do this, on Windows 7/8 at least.

It turns out an ICO file doesn't just contain one image, it contains 9 different images at 9 different resolutions:

  • 16x16
  • 24x24
  • 32x32
  • 48x48
  • 64x64
  • 72x72
  • 80x80
  • 96x96
  • 128x128

On Windows 7 and 8, the 64x64 image is used on the taskbar, and the 16x16 image is used on the icon which is placed on the top left hand corner of your form.

You can use a tool like Greenfish Icon Editor Pro (I don't work for them or anything, this isn't a plug!) to have these as two seperate images, and then add this *.ico file as normal to your Windows Form/WPF form in Visual Studio.

The end result is shown below:

WPF

As you can see my WPF application has two seperate icons, one in the taskbar and another on the form.

like image 29
JMK Avatar answered Nov 24 '22 10:11

JMK