1.设置窗体属性:ShowInTaskbar=false;
2.添加NotifyIcon控件并设置属性:Icon
3.添加窗体最小化事件
1 private void Form1_SizeChanged(object sender, System.EventArgs e)
2 {
3 if (this.WindowState == FormWindowState.Minimized)
4 {
5 this.Hide(); // 隐藏窗体
6 this.notifyIcon1.Visible = true; // 设置NotifyIcon控件可见
7 }
8 }
2 {
3 if (this.WindowState == FormWindowState.Minimized)
4 {
5 this.Hide(); // 隐藏窗体
6 this.notifyIcon1.Visible = true; // 设置NotifyIcon控件可见
7 }
8 }
4.添加图标事件(点击一下右下角的图标恢复窗体)
1 private void notifyIcon1_Click(object sender, System.EventArgs e)
2 {
3 this.Validate = true; // 显示窗体
4 this.WindowState = FormWindowState.Normal; // 设置窗体状态
5 this.notifyIcon1.Visible = false; // 设置NotifyIcon控件不可见
6 }
2 {
3 this.Validate = true; // 显示窗体
4 this.WindowState = FormWindowState.Normal; // 设置窗体状态
5 this.notifyIcon1.Visible = false; // 设置NotifyIcon控件不可见
6 }
如果在主窗体中加入一个ContextMenu控件,并设置NotifyIcon控件的ContextMenu行为,就可以做一个右击图标有相应的菜单,这里不再举例,更多的自己去发现
浙公网安备 33010602011771号