C# 程序关闭托盘图标不会自动消失
来源:互联网 发布:js怎么遍历对象数组 编辑:程序博客网 时间:2024/05/16 15:24
调试winform程序的时候使用托盘图标遇到关闭了程序但是托盘图标并没有消失的情况,但是鼠标滑过图标就消失了,这样软件打开关闭次数多了会出现在托盘堆积大量图标的情况,开始以为是操作系统刷新问题,后来使用手动释放图标资源问题解决。
具体就是使用如下方法:Dispose()Releases all resources used by the Component.(继承自 Component。)
在form的closing事件中直接调用
Releases all resources used by the Component.(继承自 Component。)
this.notifyIcon1.disponse()
也可以参考官方示例
using System;using System.Drawing;using System.Windows.Forms;public class Form1 : System.Windows.Forms.Form{ private System.Windows.Forms.NotifyIcon notifyIcon1; private System.Windows.Forms.ContextMenu contextMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.ComponentModel.IContainer components; [STAThread] static void Main() { Application.Run(new Form1()); } public Form1() { this.components = new System.ComponentModel.Container(); this.contextMenu1 = new System.Windows.Forms.ContextMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); // Initialize contextMenu1 this.contextMenu1.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] {this.menuItem1}); // Initialize menuItem1 this.menuItem1.Index = 0; this.menuItem1.Text = "E&xit"; this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click); // Set up how the form should be displayed. this.ClientSize = new System.Drawing.Size(292, 266); this.Text = "Notify Icon Example"; // Create the NotifyIcon. this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); // The Icon property sets the icon that will appear // in the systray for this application. notifyIcon1.Icon = new Icon("appicon.ico"); // The ContextMenu property sets the menu that will // appear when the systray icon is right clicked. notifyIcon1.ContextMenu = this.contextMenu1; // The Text property sets the text that will be displayed, // in a tooltip, when the mouse hovers over the systray icon. notifyIcon1.Text = "Form1 (NotifyIcon example)"; notifyIcon1.Visible = true; // Handle the DoubleClick event to activate the form. notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick); } protected override void Dispose( bool disposing ) { // Clean up any components being used. if( disposing ) if (components != null) components.Dispose(); base.Dispose( disposing ); } private void notifyIcon1_DoubleClick(object Sender, EventArgs e) { // Show the form when the user double clicks on the notify icon. // Set the WindowState to normal if the form is minimized. if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal; // Activate the form. this.Activate(); } private void menuItem1_Click(object Sender, EventArgs e) { // Close the form, which closes the application. this.Close(); }}
0 0
- C# 程序关闭托盘图标不会自动消失
- C# 程序关闭托盘图标不会自动消失
- Windows关闭程序托盘图标不能消失的原因
- Delph-- 关闭程序后托盘图标显示
- Delph-- 关闭程序后托盘图标显示
- 为什么状态栏上的GPS图标在GPS程序退出后不会自动消失
- [MFC]托盘图标删除后不自动消失的问题
- QT程序退出后托盘图标不消失问题
- QT程序退出后托盘图标不消失问题
- C#托盘图标
- C#实现托盘图标
- C#实现托盘图标
- SWT 中实现最小化到托盘图标,并只能通过托盘的弹出菜单关闭程序
- SWT 中实现最小化到托盘图标,并只能通过托盘的弹出菜单关闭程序
- 建立程序托盘图标
- winform程序托盘图标
- gtk托盘图标程序
- 浅谈c#实现隐藏任务栏图标的Windows托盘程序
- PVANET: Deep but Lightweight Neural Networks for Real-time Object Detection
- 用eclipse编译,结果出现“错误:找不到或无法加载主类”
- java 设计模式 —— 浅析状态模式
- iOS面试题
- 2路归并排序算法(C语言)
- C# 程序关闭托盘图标不会自动消失
- java文件操作
- lintcode(E) 二叉树最小深度
- Bellman-Ford单源最短路径+优化
- 深度学习框架Caffe源码解析
- java多线程之join
- 基于TI-RTOS的CC2650DK开发(11)---信号量
- 哈夫曼编码/译码的设计与实现
- JDBC第二篇--【PreparedStatment、批处理、处理二进制、自动主键、调用存储过程】