1

i need to minimize app to system tray (see my icon there). But after starting the app, the icon dissapears from taskbar (that is fine) but i cannot see it in system tray (that is bad).

enter image description here

Where can be a mistake, please? PS: i am using WPF.

This is inner code of my event:

System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon();
            if (WindowState.Minimized == this.WindowState)
            {
                notifyIcon.Visible = true;
                notifyIcon.BalloonTipText = "Radek app";
                notifyIcon.BalloonTipTitle = "Welcome Message";
                notifyIcon.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;                
                notifyIcon.ShowBalloonTip(3000);                
                this.ShowInTaskbar = false;
            }

            else if (WindowState.Normal == this.WindowState)
            {
                this.WindowState = WindowState.Normal;
                this.ShowInTaskbar = true;
                notifyIcon.Visible = false;
            }
user7968180
  • 145
  • 1
  • 15

2 Answers2

3

That Info icon is for the balloon, not the TrayIcon itself, you should add your image (I recommend 16x16px png file) to your application resources, then you can use it like:

var iconHandle = Properties.Resources.YourIconImage.GetHicon();
NotifyIcon.Icon = System.Drawing.Icon.FromHandle(iconHandle);
Mohamad Rashidi
  • 307
  • 2
  • 14
  • Outstanding :-) it works, icon is set. This question is gonna be very usefull to everyone, it includes everything. – user7968180 Jun 13 '17 at 11:53
2

You need to set the Icon as shown below:

notifyIcon.Icon = new System.Drawing.Icon(Path to your Icon);
Abhishek
  • 2,925
  • 4
  • 34
  • 59
  • I have problem to find picture usable as icon (and put string path to the argument), i am gonna create a new question for it. Then i can try your solution. – user7968180 Jun 13 '17 at 11:07