winform应用窗体默认无最小化到系统托盘的,而是在任务栏。

  1. 添加notifyIcon控件,给一个Icon,给一个点击事件
if (this.WindowState == FormWindowState.Minimized)
{
       this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
       this.notifyIcon1.Visible = false;
       this.ShowInTaskbar = true;   
       this.Show();
   }
  1. form窗体给一个SizeChanged()事件,点击最小化按钮,会触发SizeChanged事件,在事件中将任务图标展示到托盘中,并隐藏窗体,关闭取消显示在任务栏上。
 if (this.WindowState == FormWindowState.Minimized)
 {
      this.ShowInTaskbar = false;
      this.Hide();
      this.notifyIcon1.Visible = true;
  }
  1. notifyIcon 还具有气泡提示功能
this.notifyIcon1.ShowBalloonTip(3000, "运行成功", " ", ToolTipIcon.Info);

在这里插入图片描述

更多推荐