系统任务栏图标 [英] System Tray Icon

查看:175
本文介绍了系统任务栏图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,我正在开发一个带有系统任务栏的应用程序,我的问题是,在关闭我的应用程序时,它应该从系统任务栏中删除任务栏图标,但是并没有刷新任务栏.为什么?
您的帮助将不胜感激……以下是我的代码...

Hi friends,I am developing an application with system tray, my problem is, while closing my application,it should remove the tray icon from the system tray, but it is not refreshing the task bar. why?
your help would be appreciated...... the following is my code...

private void frmMessenger_FormClosing(object sender, FormClosingEventArgs e)
        {
 notifyIcon1.Visible = false;
                notifyIcon1.Icon = null;
                notifyIcon1.Dispose();
}

推荐答案

您不需要这样做.我现在正在开发一个应用程序,该应用程序位于系统托盘中,并且我将Form.ShowInTaskBar属性设置为false-根本没有显示该属性.

如果您说关闭应用程序后图标仍保留在系统托盘中,则可以尝试以下形式的代码:

You shouldn''t need to do that. I am working on an app right now that lives in the system tray, and I have the Form.ShowInTaskBar property set to false - it never shows up there at all.

If you''re saying that the icon remains IN THE SYSTEM TRAY after closing the app, you could try this code in your form:

//---------------------------------------------------------------------
protected override void Dispose(bool disposing) 
{ 
    if (disposing) 
    { 
        this.notifyIcon1.Dispose();
    }
    base.Dispose(disposing);
}



我发现,如果将NotifyIcon控件拖到设计器中的窗体上,则当应用程序关闭时,designer.cs文件中的Dispose方法将正确处理它.但是,如果手动将其添加到.cs文件中,则必须将专门用于放置notifyIcon的行添加到designer.cs文件中的Dispose方法中.



What I''ve found is that if you drag a NotifyIcon control onto your form in the designer, the Dispose method in your designer.cs file will properly dispose it when the app closes. HOWEVER, if you add it manually to your .cs file, you have to add the line that specifically disposes your notifyIcon to the Dispose method in your designer.cs file.


尝试 [

这篇关于系统任务栏图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆