http://www.cnblogs.com/kingdi/archive/2006/09/04/494740.html 这边参看 怎么捕获 单击最小化 按钮 事件 ...
然后 结合 NotifyMenuStrip 控件 实现你要的功能.
在FORM中加入“notifyIcon”,“contextMenuStrip”;
然后:
private void Form1_Load(object sender, EventArgs e)
{//设置托盘控件属性
this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
this.notifyIcon1.Text = "演示创建托盘";
this.notifyIcon1.Visible = true;
this.notifyIcon1.Icon = new Icon("MyIcon.ico");
this.ContextMenuStrip=this.contextMenuStrip1;
}
然后:
编辑contextMenuStrip:“显示托盘”。“显示窗体”。“关闭程序”;编辑好后,双击每个项;
最后:
private void 显示托盘ToolStripMenuItem_Click(object sender, EventArgs e)
{//显示托盘
this.notifyIcon1.Visible = true;
this.Visible = false;
}
private void 显示窗体ToolStripMenuItem_Click(object sender, EventArgs e)
{//显示窗体
this.notifyIcon1.Visible = false;
this.Visible = true;
}
private void 关闭程序ToolStripMenuItem_Click(object sender, EventArgs e)
{//关闭程序
this.Close();
}