建立一个 contextMenu1 上面有4个菜单项,miShowWindow,miShowIcon,miShowAll,miExit
然后设置主窗体和notifyIcon(此处实例是ni)的contextMenu为此contextMenu1,单击菜单可以看到效果,如果最小化也要推到托盘的话,可能要用到其它事件 ................................................................. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Notify
{ public partial class Notify : Form { public Notify() { InitializeComponent(); } private void miShowWindow_Click(object sender, EventArgs e)
{ //显示窗体 this.Visible = true; this.ni.Visible = false; } private void miShowAll_Click(object sender, EventArgs e)
{ //显示全部 this.Visible = true; this.ni.Visible = true; } private void miShowIcon_Click(object sender, EventArgs e)
{ //显示托盘 this.Visible = false; this.ni.Visible = true; } private void miExit_Click(object sender, EventArgs e)
{ Application.Exit(); } private void ni_Click(object sender, EventArgs e)
{ //显示托盘 miShowWindow_Click(sender, e); } } } |
|