Issue with NotifyIcon not disappearing on Winforms App

前端 未结 7 1839
暗喜
暗喜 2020-12-16 17:38

I\'ve got a .Net 3.5 C# Winforms app. It\'s got no GUI as such, just a NotifyIcon with a ContextMenu.

I\'ve tried to set the NotifyIcon to visible=false and dispose

7条回答
  •  长情又很酷
    2020-12-16 17:45

    This is what I'm doing in WPF.

    I am using this in conjunction to David Anson's Minimize to tray sample app, which lets you hook up a tray icon to a window (you may have multiple windows open).

    Just added this code to the constructor for MinimizeToTrayInstance.

    _window.Closed += (s, e) => 
    {
            if (_notifyIcon != null)
            {
                _notifyIcon.Visible = false;
                _notifyIcon.Dispose();
                _notifyIcon = null;
            }
    };
    

提交回复
热议问题