dotnet/winforms

NotifyIcon does not use the appropriate icon size

开放

#6,955 创建于 2022年4月2日

 (6 条评论) (1 个反应) (0 位负责人)C# (922 个派生)batch import
:beetle: bugarea-System.Drawingarea-Theminghelp wanted

仓库指标

星标
 (4,100 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

.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.

贡献者指南