/// <summary> /// Minimize the window and hide it from the TaskBar. /// </summary> public void MinimizeToTray(bool showBalloonTip, bool minimizeToTray) { // Show only first time. if (showBalloonTip) { TrayNotifyIcon.BalloonTipText = Application.ProductName; // Show balloon tip for 2 seconds. TrayNotifyIcon.ShowBalloonTip(2, "X360CE", Application.ProductName, ToolTipIcon.Info); } // hold - program. // NOTE: also it would be possible to track which direction mouse will move in or move out on TrayIcon. // For example: open program if mouse moves in from left and moves out from top. TrayNotifyIcon.Text = "X360CE: Double click - program, click - menu."; if (minimizeToTray) { // Set window style as ToolWindow to avoid its icon in ALT+TAB. if (Owner != _hiddenForm) { Owner = _hiddenForm; } // Hide form bar from the TarkBar. if (ShowInTaskbar) { ShowInTaskbar = false; } } if (WindowState != FormWindowState.Minimized) { WindowState = FormWindowState.Minimized; } }
private void MainForm_Resize(object sender, EventArgs e) { if (WindowState == FormWindowState.Minimized) { MinimizeToTray(); TrayNotifyIcon.ShowBalloonTip(1000); } }
private void TrayNotifyIcon_Click(object sender, EventArgs e) { var mi = TrayNotifyIcon.GetType().GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic); mi.Invoke(TrayNotifyIcon, null); }
private void ExitApplication(object sender, EventArgs e) { TrayNotifyIcon.Dispose(); Environment.Exit(0); }