C#实现右下角图标(系统托盘)功能(转)
已经试验过,可以使用,备份留着以后参考
窗体中拖入 notifyIcon 组件
notifyIcon 中的 ICON 属性 显示的图标
下面是系统托盘的基本功能代码(单击最小化窗体隐藏,双击图标显示)及窗体关闭时退出确认代码。
//单击最小化窗体隐藏 private void frmMain_SizeChanged(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Normal) { notifyIcon1.Visible = true; //托盘图标隐藏 } if (this.WindowState == FormWindowState.Minimized)//最小化事件 { this.Hide();//最小化时窗体隐藏 } } //双击系统托盘的小图标事件 private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Show(); this.WindowState = FormWindowState.Normal; //还原窗体 } } private void frmMain_FormClosing(object sender, FormClosingEventArgs e) //关闭事件 { DialogResult result; result = MessageBox.Show("确定退出吗?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { Application.ExitThread(); } else { e.Cancel = true; } }
浙公网安备 33010602011771号