C#程序最小化到托盘图标操作步骤与实现代码
程序员文章站
2023-12-11 23:21:58
复制代码 代码如下: // this.sizechanged += new system.eventhandler(this.form1_sizechanged); //上...
复制代码 代码如下:
// 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;
}
}
.添加点击图标事件(首先需要添加事件引用):
private void notifyicon1_click(object sender, eventargs e)
{
this.visible = true;
this.windowstate = formwindowstate.normal;
this.notifyicon1.visible = false;
}
.可以给notifyicon添加右键菜单:
主窗体中拖入一个contextmenu控件contextmenu1,点中控件,在上下文菜单中添加菜单,notifyicon1的contextmenu行为中选中contextmenu1作为上下文菜单。
(可以在子菜单中添加行为)