// end of background worker

        public void trayActivatePlan(Object sender, EventArgs e)
        {
            foreach (PowerPlan p in PowerPlan.getAll())
            {
                if (String.Compare(p.elementName, sender.ToString(), true) == 0 &&
                    p.isActive == false)    // don't switch if already active
                {
                    p.activate();
                    statusLabel.Text = "Active Plan : " + p.elementName + "\n\n" + p.description;
                    trayIcon.ShowBalloonTip(20, "Power Plan Changed", p.elementName, ToolTipIcon.Info);
                    break;
                }
            }
        }
        public mainWin()
        {
            InitializeComponent();
            this.WindowState   = FormWindowState.Minimized;
            this.ShowInTaskbar = false;
            this.Location      = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
            this.Hide();

            // Add all power plans to tray context menu and combo box
            foreach (PowerPlan p in PowerPlan.getAll())
            {
                trayContextMenuStrip.Items.Add(
                    new System.Windows.Forms.ToolStripMenuItem(p.elementName, null,
                                                               new EventHandler(trayActivatePlan)));
                if (p.isActive)
                {
                    statusLabel.Text = "Active Plan : " + p.elementName + "\n\n" + p.description;
                    trayIcon.ShowBalloonTip(20, "Active Power Plan", p.elementName, ToolTipIcon.Info);
                }
            }
            // Sort tray context menu
            ToolStripMenuItem[] tmp = new ToolStripMenuItem[trayContextMenuStrip.Items.Count];
            trayContextMenuStrip.Items.CopyTo(tmp, 0);
            Array.Sort(tmp,
                       delegate(ToolStripMenuItem tsiA, ToolStripMenuItem tsiB)
            {
                return(tsiA.Text.Replace("&", string.Empty).CompareTo(tsiB.Text.Replace("&", string.Empty)));
            });
            trayContextMenuStrip.Items.Clear();
            trayContextMenuStrip.Items.AddRange(tmp);

            // Add exit to tray context menu
            System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            exitToolStripMenuItem.Font   = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            exitToolStripMenuItem.Text   = "Exit";
            exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
            trayContextMenuStrip.Items.Add(exitToolStripMenuItem);
        }