C# NotifyIcon 托盘控件

右下角以图标形式显示,双击图标显示界面,最小化界面时不显示在任务栏。

第一步:在界面上添加NotifyIcon控件。

 


 

第二步:设置notifyIcon1的属性,添加图标,将Visible设为true。当然,Visible也可以在代码中设置,true是显示在右下角,false不显示。


第三步:notifyIcon1添加事件,即双击显示界面。

1 private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
2 {
3     this.Show();//显示界面
4     this.WindowState = FormWindowState.Normal;
5     this.ShowInTaskbar = true;//显示在任务栏
6 }

 


第四步:最小化界面时不显示在任务栏。

1 private void FormMain_Resize(object sender, EventArgs e)
2 {
3     if (this.WindowState == FormWindowState.Minimized)
4     {
5         this.Hide();
6         this.ShowInTaskbar = false;
7     }
8 }

 

posted @ 2018-12-05 10:40  格格_gloria  阅读(1052)  评论(0编辑  收藏  举报