protected void RegenTrayMenu() { pwrNames = PwrList.getPlansList(); PowerPlan active = PwrList.getCurrActivePlan(); trayMenu = new ContextMenu(); trayMenu.MenuItems.Add("Power Plans:").Enabled = false; MenuItem curr; foreach (PowerPlan p in pwrNames) { curr = trayMenu.MenuItems.Add(p.name, ChangePlan); if (p.name == active.name) { curr.Checked = true; } else { } } trayMenu.MenuItems.Add("-"); trayMenu.MenuItems.Add("Refresh Plans", OnRefresh); trayMenu.MenuItems.Add("Open Control panel", OpenCtrlPanel); trayMenu.MenuItems.Add("-"); trayMenu.MenuItems.Add("About", ShowAbout); trayMenu.MenuItems.Add("Exit", OnExit); }
private void ChangePlan(object sender, EventArgs e) { MenuItem mi = (MenuItem)sender; // find the plan foreach (PowerPlan p in pwrNames) { if (mi.Text == p.name) { // found the plan! now set it if (PwrList.setPlan(p)) { ClearChecked(); mi.Checked = true; } else { Console.WriteLine("Plan change failed."); } break; } } }