The problem with using the icon directly in your resources is that instead of choosing the correct version of the icon in your icon file, the infrastructure simply scales the default version of the icon regardless of the size of the notification area. That is why you see jagged edges.
To get the best quality, you will need to choose the right size in your badge yourself.
First, instead of directly NotifyIcon.Icon
your NotifyIcon.Icon
to an icon in your resources, create a new instance of Icon
. This will allow you to select a specific icon size in the icon resource. Using SystemInformation.SmallIconSize
, you will get the size needed for the notification area.
So:
myNotifyIcon.Icon = new Icon(Properties.Resources.MyIcon, SystemInformation.SmallIconSize);
Now SystemInformation.SmallIconSize
always returns the correct icon size, but only if your application supports DPI (otherwise it always returns 16). If your application does not support DPI, and it is used in a system where DPI scaling is enabled, the line above will select the 16x16 icon in your resource, while it will scale to any size that is required for the notification area (in other words, the ugly icon )
By providing your DPI community with an application, SystemInformation.SmallIconSize
will return the correct size given DPI scaling. For example, if the DPI scaling is 150%, SystemInformation.SmallIconSize
will return 24 (16 ร 1.5).
For your application to recognize DPI, just add it to your app.manifest inside the <asmv1:assembly>
:
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" > <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings"> <dpiAware>true</dpiAware> </asmv3:windowsSettings> </asmv3:application>
source share