private void PrintService_SizeChanged(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Hide(); this.notifyIcon.Visible = true; } } private void PrintService_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("是否关闭服务", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) e.Cancel = true; } private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show("是否确认退出程序?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { // 关闭所有的线程 this.Dispose(); this.Close(); } } private void 显示ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Show(); this.ShowInTaskbar = true; this.WindowState = FormWindowState.Normal; notifyIcon.Visible = false; } }
参考:http://www.cnblogs.com/nangong/p/997995dc3743b60baac30899c3d82ef7.html
http://www.cnblogs.com/_zjl/archive/2011/05/16/2047918.html WinForm中实现最小化到系统托盘
http://www.cnblogs.com/xugang/archive/2007/12/19/1006005.html C#实现WinForm窗口最小化到系统托盘