上网搜了搜 自己改写了下
首先把form的 showtaskBar 设为 false;
再添加notifyIcon控件 notifyIcon1 ,icon属性里改为你要用的图标,visible设为false 因为初始不显示托盘图标,当然你也可以开始就显示
代码里输入
private bool show ;//一个flag
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized) {//判断是否最小化
this.Visible = false;//隐藏
this.notifyIcon1.Visible = true;
show = false;
}
}
private void notifyIcon1_DoubleClick(object sender, System.EventArgs e) {
if (!show)
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
show = true;
}
else if (show) {
this.Visible = false;
this.WindowState = FormWindowState.Minimized;
show = false;
}
}
基本就是这样.