C#实现系统托盘,C#窗体最小化时隐藏为任务栏图标的Window appllication
1.设置窗体属性showintask=false
2.加notifyicon控件notifyicon1,为控件notifyicon1的属性icon添加一个icon图标。
3.添加窗体最小化事件(首先需要添加事件引用):
//this.sizechanged+=newsystem.eventhandler(this.form1_sizechanged);
//上面一行是主窗体initializecomponent()方法中需要添加的引用
privatevoidform1_sizechanged(objectsender,eventargse)
{
if(this.windowstate==formwindowstate.minimized)
{
this.hide();
this.notifyicon1.visible=true;
}
}
4.添加点击图标事件(首先需要添加事件引用):
privatevoidnotifyicon1_click(objectsender,eventargse)
{
this.visible=true;
this.windowstate=formwindowstate.normal;
this.notifyicon1.visible=false;
}
*若要在窗体运行时就最小化到托盘,在Form初始化函数内添加:this.windowstate=formwindowstate.minimized