C # Minimize to tray + double-click the tray recovery

C # Minimize to tray + double-click the tray recovery

2012 August 20 18:06:45  Claude- lake  Reads 12952

1. Add notifyIcon controls, and add Icon, otherwise there is no tray icon (right tray menu can also be added directly in the property);

 

2. Form a response message SizeChanged or Resize:

 
  1. // Hide to system tray

  2. private void Form1_Resize(object sender, EventArgs e)

  3. {

  4. if (this.WindowState == FormWindowState.Minimized)

  5. {

  6. this.Hide();

  7. this.ShowInTaskbar = false;

  8. this.notifyIcon.Visible = true;

  9. }

  10. }

 

3. Double-click the tray icon to restore the required response notifyIcon DoubleClick message:

 
  1. // Show from system tray

  2. private void notifyIcon_DoubleClick(object sender, EventArgs e)

  3. {

  4. if (this.WindowState == FormWindowState.Minimized)

  5. {

  6. this.Show();

  7. this.WindowState = FormWindowState.Normal;

  8. notifyIcon.Visible = false;

  9. this.ShowInTaskbar = true;

  10. }

  11. }

 

 

Guess you like

Origin blog.csdn.net/cxu123321/article/details/93380478