C# Minimize to system tray on close

前端 未结 7 1129
再見小時候
再見小時候 2020-12-28 09:10

Hi In my c# application I am trying to minimize application to systems tray, when the form is closed. Here is the code I have tried.

   public void MinimizeT         


        
7条回答
  •  伪装坚强ぢ
    2020-12-28 09:22

    e.Cancel = true; code will be always cancelling the event even if you shut the computer down, but here is a code that helps you:

     private void Form1_FormClosing(object sender, FormClosingEventArgs e)
     {
         if (e.CloseReason == CloseReason.UserClosing)
         {
              myNotifyIcon.Visible = true;
              this.Hide();
              e.Cancel = true;
         }
     }
    

    It will allow closing the form programmaticaly.

提交回复
热议问题