dotnet/winforms

NotifyIcon does not use the appropriate icon size

Open

#6.955 aberto em 2 de abr. de 2022

Ver no GitHub
 (6 comments) (1 reaction) (0 assignees)C# (922 forks)batch import
:beetle: bugarea-System.Drawingarea-Theminghelp wanted

Métricas do repositório

Stars
 (4.100 stars)
Métricas de merge de PR
 (Mesclagem média 14d 22h) (56 fundiu PRs em 30d)

Description

.NET version

6.0

Did it work in .NET Framework?

No

Did it work in any of the earlier releases of .NET Core or .NET 5+?

No response

Issue description

There is a long-known issue that NotifyIcon does not use the proper icon size. Rather than using the small icon size, it takes whatever size the System.Drawing.Icon has been constructed for (usually the default icon size), which Windows then scales down to the small icon size.

There is a work-around:

_notifyIcon.Icon = new Icon(_notifyIcon.Icon, SystemInformation.SmallIconSize);

NotifyIcon should do this itself.

Steps to reproduce

  1. Create a new WinForms project, name it "NotifyIconBug".
  2. Add a resource file and name it Resource1.resx.
  3. Add an icon with sizes of 16x16 and 32x32 to the Resource1.resx and name it application_icon. Use images for the two sizes of the icon that are distinguishable from one another.
  4. Add a NotifyIcon to Form1 and name it notifyIcon1.
  5. Set the Icon property of the NotifyIcon to the icon: notifyIcon1.Icon = Resource1.application_icon;
  6. Run the project, having the notification area on a low-DPI display. The 32x32 size of the icon is displayed scaled down to 16x16 rather than displaying the 16x16 size.

I'd guess you could also recreate this on a high-DPI display as well if you scale up the above sizes accordingly.

Guia do colaborador