dotnet/winforms

NotifyIcon does not use the appropriate icon size

Open

#6,955 建立於 2022年4月2日

在 GitHub 查看
 (6 留言) (1 反應) (0 負責人)C# (922 fork)batch import
:beetle: bugarea-System.Drawingarea-Theminghelp wanted

倉庫指標

Star
 (4,100 star)
PR 合併指標
 (平均合併 14天 22小時) (30 天內合併 56 個 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.

貢獻者指南