简体   繁体   English

使用.net和C#从任务栏中删除应用程序图标

[英]remove application icon from the taskbar using .net with c#

I am trying to show icon on the taskbar, well i did this in this way. 我正在尝试在任务栏上显示图标,好吧,我是这样做的。

ResourceManager resManager = new ResourceManager("TestAgent.Properties.Resources", GetType().Module.Assembly);
                notifyicon.Icon = (Icon)resManager.GetObject("TestAgent");
                notifyicon.Visible = true;
                notifyicon.Text = "Test Agent";
                this.Hide();
                this.ShowInTaskbar = false;
                this.SetVisibleCore(false); 

On other side when try remove icon from the taskbar doing in this way. 另一方面,尝试以这种方式从任务栏中删除图标。

notifyicon.Visible = false;
            notifyicon = null;
            rulehandler = null;

I did this successfully but the problem is when try to remove icon from the taskbar it remove icon successfully from the taskbar but not hide the icon, When hover the mouse on the icon it removes. 我成功完成了此操作,但问题是当尝试从任务栏删除图标时,它成功从任务栏删除了图标,但没有隐藏图标,将鼠标悬停在图标上时,它删除了。

Is there anyway to remove icon without mouse hover? 反正有没有鼠标悬停删除图标? I am doing this in windows form with c# 我正在用C#在Windows窗体中执行此操作

Simply Dispose it. 简单地处理它。

In a Windows Form you can subscribe to the global event ApplicationExit ... 在Windows窗体中,您可以订阅全局事件ApplicationExit ...

Application.ApplicationExit += new EventHandler(this.OnApplicationExit);

private void OnApplicationExit(object sender, EventArgs e) {
     notifyicon.Dispose();
}

simply write notifyIcon.Visible = false; 只需编写notifyIcon.Visible = false; (capital I in Icon) before closing the window, and you are good to go. (在Icon中用大写字母I表示),然后再关闭窗口,这样您就可以开始了。 As simple as that. 就如此容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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