|
1.设置窗体属性showintask=false
2.加notifyicon控件notifyicon1,为控件notifyicon1的属性icon添加一个icon图标。
3.添加窗体最小化事件(首先需要添加事件引用):
// this.sizechanged += new system.eventhandler(this.form1_sizechanged);
//上面一行是主窗体initializecomponent()方法中需要添加的引用
private void form1_sizechanged(object sender, eventargs e) { if (this.windowstate==formwindowstate.minimized) { this.hide(); this.notifyicon1.visible=true; }
} | 4.添加点击图标事件(首先需要添加事件引用):
private void notifyicon1_click(object sender, eventargs e) { this.visible = true;
this.windowstate = formwindowstate.normal;
this.notifyicon1.visible = false; } |
5.可以给notifyicon添加右键菜单:
主窗体中拖入一个contextmenu控件contextmenu1,点中控件,在上下文菜单中添加菜单,notifyicon1的contextmenu行为中选中contextmenu1作为上下文菜单。
(可以在子菜单中添加行为) |