Exemplo n.º 1
0
 /// <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;
     }
 }
Exemplo n.º 2
0
 private void MainForm_Resize(object sender, EventArgs e)
 {
     if (WindowState == FormWindowState.Minimized)
     {
         MinimizeToTray();
         TrayNotifyIcon.ShowBalloonTip(1000);
     }
 }
Exemplo n.º 3
0
        private void TrayNotifyIcon_Click(object sender, EventArgs e)
        {
            var mi = TrayNotifyIcon.GetType().GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);

            mi.Invoke(TrayNotifyIcon, null);
        }
Exemplo n.º 4
0
 private void ExitApplication(object sender, EventArgs e)
 {
     TrayNotifyIcon.Dispose();
     Environment.Exit(0);
 }