0

This question is different from others because I've already tried their solutions:

  • visible=true;
  • balloon tips also don't show;
  • and it's not in the "extended icons" section of the system tray (or whatever that's called where hidden icons go).

The code, taken from a number of different answers across SO and other places (they all say the same):

    private void mainform_Resize(object sender, EventArgs e)
    {
        if (FormWindowState.Minimized == this.WindowState)
        {
            notifyIcon.Visible = true;
            notifyIcon.ShowBalloonTip(500, "test title", "test message", ToolTipIcon.Info);
            this.Hide();
        }
        else if (FormWindowState.Normal == this.WindowState)
        {
            notifyIcon.Visible = false;
        }
    }

Expected result: icon shows in system tray. Actual result: nothing happens, only the window disappears as per this.Hide();.

Luc
  • 5,339
  • 2
  • 48
  • 48

1 Answers1

2

What nobody mentions is that an icon is compulsory. After almost an hour of searching I decided I'd try giving it a random icon, using Everything to search for a random .ico file on my system. Lo and behold, this makes the icon show up:

notifyIcon.Icon = new Icon(@"C:\path\to\random\icon.ico");

Apparently without icon, the default is to silently fail. There is no default icon, nor will an empty tile show up, it will just completely ignore you.

Bonus: if you want to use your form's icon, you can use:

notifyIcon.Icon = this.Icon;
Luc
  • 5,339
  • 2
  • 48
  • 48
  • 1
    Well NotifyIcon is for the system tray. ;) No icon = no system tray item – TyCobb May 04 '16 at 16:43
  • 2
    @TyCobb I'd agree except: the form has an icon by default, why not the system tray? And if it doesn't have a default, it should totally raise some sort of exception (or at least warning!) if it's not set. It knows you're trying to display it (`visible=true`) and it knows it cannot (no icon). – Luc May 04 '16 at 16:50