实现系统托盘程序控制
1private void frmMain_Load(object sender, System.EventArgs e)
2 {
3 //显示托盘图标
4 this.Visible=false;
5 this.notifySys.Visible=true;
6 }
7
8 /// <summary>
9 /// 显示托盘图标
10 /// </summary>
11 /// <param name="sender"></param>
12 /// <param name="e"></param>
13 private void menuItem2_Click(object sender, System.EventArgs e)
14 {
15 //显示托盘图标
16 this.Visible=false;
17 this.notifySys.Visible=true;
18 }
19
20 /// <summary>
21 /// 显示主窗体
22 /// </summary>
23 /// <param name="sender"></param>
24 /// <param name="e"></param>
25 private void menuItem3_Click(object sender, System.EventArgs e)
26 {
27 //显示主窗体
28 this.Visible=true;
29 this.notifySys.Visible=true;
30 }
31
32 /// <summary>
33 /// 关闭程序
34 /// </summary>
35 /// <param name="sender"></param>
36 /// <param name="e"></param>
37 private void menuItem4_Click(object sender, System.EventArgs e)
38 {
39 //关闭程序
40 this.notifySys.Visible=false;
41 this.Close();
42 Application.Exit();
43 }
44
45 /// <summary>
46 /// 关于程序
47 /// </summary>
48 /// <param name="sender"></param>
49 /// <param name="e"></param>
50 private void menuItem10_Click(object sender, System.EventArgs e)
51 {
52 frmAbout about = new frmAbout();
53 about.Show();
54 }
55
56 private void frmMain_SizeChanged(object sender, System.EventArgs e)
57 {
58 if (this.WindowState == FormWindowState.Minimized)
59 {
60 this.Hide();
61 this.notifySys.Visible = true;
62 }
63 }
64
65 private void notifySys_DoubleClick(object sender, System.EventArgs e)
66 {
67 this.Visible = true;
68 this.WindowState = FormWindowState.Normal;
69 this.notifySys.Visible = false;
70 }
71
72 private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
73 {
74 //显示托盘图标
75 //this.Visible=false;
76 this.notifySys.Visible=true;
77 this.Hide();
78 e.Cancel = true;
79 }
2 {
3 //显示托盘图标
4 this.Visible=false;
5 this.notifySys.Visible=true;
6 }
7
8 /// <summary>
9 /// 显示托盘图标
10 /// </summary>
11 /// <param name="sender"></param>
12 /// <param name="e"></param>
13 private void menuItem2_Click(object sender, System.EventArgs e)
14 {
15 //显示托盘图标
16 this.Visible=false;
17 this.notifySys.Visible=true;
18 }
19
20 /// <summary>
21 /// 显示主窗体
22 /// </summary>
23 /// <param name="sender"></param>
24 /// <param name="e"></param>
25 private void menuItem3_Click(object sender, System.EventArgs e)
26 {
27 //显示主窗体
28 this.Visible=true;
29 this.notifySys.Visible=true;
30 }
31
32 /// <summary>
33 /// 关闭程序
34 /// </summary>
35 /// <param name="sender"></param>
36 /// <param name="e"></param>
37 private void menuItem4_Click(object sender, System.EventArgs e)
38 {
39 //关闭程序
40 this.notifySys.Visible=false;
41 this.Close();
42 Application.Exit();
43 }
44
45 /// <summary>
46 /// 关于程序
47 /// </summary>
48 /// <param name="sender"></param>
49 /// <param name="e"></param>
50 private void menuItem10_Click(object sender, System.EventArgs e)
51 {
52 frmAbout about = new frmAbout();
53 about.Show();
54 }
55
56 private void frmMain_SizeChanged(object sender, System.EventArgs e)
57 {
58 if (this.WindowState == FormWindowState.Minimized)
59 {
60 this.Hide();
61 this.notifySys.Visible = true;
62 }
63 }
64
65 private void notifySys_DoubleClick(object sender, System.EventArgs e)
66 {
67 this.Visible = true;
68 this.WindowState = FormWindowState.Normal;
69 this.notifySys.Visible = false;
70 }
71
72 private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
73 {
74 //显示托盘图标
75 //this.Visible=false;
76 this.notifySys.Visible=true;
77 this.Hide();
78 e.Cancel = true;
79 }