3

I am having trouble making a NotifyIcon in Windows 10 whose icon resource looks anything but a blurry mess.

Icon

This happens with both icons from the SystemIcons class, or my own using Properties.Resources. I have tried creating a new instance of the icon with the Icon (Icon original, int width, int height) constructor, and all sorts of other mad things, including this nugget:

Icon ico = Icon.FromHandle((new Icon(Resources.InfoIcon, 256, 256).ToBitmap()).GetHicon());

to no avail. Any advice would be appreciated!

Thanasi Poulos
  • 278
  • 3
  • 16
  • Have you tried to display the resources with their original dimensions? – Stefan Feb 06 '16 at 15:02
  • I'm not entirely certain what you mean, but the .ico file I have there contains 9 icons, from 256x256 right down to 16x16, and I have tried all the sizes manually to no avail. – Thanasi Poulos Feb 06 '16 at 15:03
  • @HansPassant, In fact, that was the first method I used to try and display a `NotifyIcon`. It does not display anything... unless you give it an icon parameter, which it promptly ignores. (A fact I literally just now discovered). This would also mean I cannot use custom icons. As for that linked post, it did not work for me; maybe something to do with VS 2015? – Thanasi Poulos Feb 06 '16 at 15:34
  • It sure looks like trash – tofutim Feb 27 '16 at 01:01

1 Answers1

5

The poor icon in the screenshot is easy to address, you forgot to set the NotifyIcon.BalloonTipIcon property. Or use the NotifyIcon.ShowBalloonTip() method overload that takes ToolTipIcon. With ToolTipIcon.Info you'll get the high resolution system default icon. For example:

    notifyIcon1.ShowBalloonTip(5000, "eDIDIO", 
        "Connected successfully!", ToolTipIcon.Info);

Which produces:

enter image description here

If you want your own icon to show up in this notification "balloon" then you have to work around a restriction in the ResourceManager.GetObject() method. Which is what you are using when you write "Resources.InfoIcon". GetObject() does not have enough arguments to be selective about the icon size you prefer. Use the code shown in this answer. Never use GetHicon() btw, it does a very poor job at color palette mapping and can only produce a 16 color icon.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thanks, I can now get nice icons if I want to use default ones (which honestly, I probably will). The answer you linked to does not give me any resources though. Additionally, why is it that i have to set the `NotifyIcon.Icon` property _as well as_ the `NotifyIcon.BalloonTipIcon` property to get the `BalloonTipIcon` to show? – Thanasi Poulos Feb 06 '16 at 15:38
  • The Icon and BalloonTipIcon are very different properties. BalloonTipIcon is not an Icon type property, it is an enum. – Hans Passant Feb 06 '16 at 15:41
  • Hans, I would like to use ToolTipIcon.None and have it pull my own Icon, but what size do I need to use to make it look nice? Will it share a 64x64 icon? – tofutim Feb 27 '16 at 01:08
  • actually, it looks like that icon is 20 – tofutim Feb 27 '16 at 01:39
  • Hans, I've been working on this for a bit, and it seems setting the NotifyIcon.Icon to different size icons doesn't make a difference - is it pulling the icon from somewhere else? – tofutim Feb 27 '16 at 01:44