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:
-
// Hide to system tray
-
private void Form1_Resize(object sender, EventArgs e)
-
{
-
if (this.WindowState == FormWindowState.Minimized)
-
{
-
this.Hide();
-
this.ShowInTaskbar = false;
-
this.notifyIcon.Visible = true;
-
}
-
}
3. Double-click the tray icon to restore the required response notifyIcon DoubleClick message:
-
// Show from system tray
-
private void notifyIcon_DoubleClick(object sender, EventArgs e)
-
{
-
if (this.WindowState == FormWindowState.Minimized)
-
{
-
this.Show();
-
this.WindowState = FormWindowState.Normal;
-
notifyIcon.Visible = false;
-
this.ShowInTaskbar = true;
-
}
-
}