简体   繁体   中英

minimize app to system tray - no icon appears

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).

在此处输入图片说明

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;
            }

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);

您需要设置图标,如下所示:

notifyIcon.Icon = new System.Drawing.Icon(Path to your Icon);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM