winform 托盘
//首先要设置notifyIcon属性:Icon设置ico图标,否则在系统托盘无图标显示
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { this.WindowState = FormWindowState.Normal; //若使用Hide()时,要用Show()方法显示窗体 } private void MainForm_Resize(object sender, EventArgs e) { this.ShowInTaskbar = this.WindowState != FormWindowState.Minimized;//最小化时不在任务栏显示 //或者如下 if (this.WindowState == FormWindowState.Minimized) Hide();//最小时隐藏 }
//设置系统托盘右击菜单
拖控件ContextMenuStrip, 在notifyIcon的ContextMenuStrip属性选择此contextMenuStrip控件。contextMenuStrip可增加菜单项点击事件