private ToolStripMenuItem Restart(JsonMenuItem item) { var menu = new System.Windows.Forms.ToolStripMenuItem(); menu.Text = item.Text; if (!String.IsNullOrEmpty(item.Image)) { menu.Image = Bitmap.FromFile(item.Image); } else { menu.Image = RestartImage; } if (!String.IsNullOrEmpty(item.Icon)) { RestartIcon = new Icon(item.Icon); } menu.Click += (sender, e) => { if (IsRun) { notifyIcon.Icon = RestartIcon; KillProcessAndChildren(MainProcess.Id); IsRun = false; MainProcess.Start(); MainProcess.StandardInput.WriteLine(RunCMD); MainProcess.StandardInput.AutoFlush = true; notifyIcon.Icon = StartIcon; IsRun = true; } }; return(menu); }
private ToolStripMenuItem Stop(JsonMenuItem item) { var menu = new System.Windows.Forms.ToolStripMenuItem(); menu.Text = item.Text; if (!String.IsNullOrEmpty(item.Image)) { menu.Image = Bitmap.FromFile(item.Image); } else { menu.Image = StopImage; } if (!String.IsNullOrEmpty(item.Icon)) { StopIcon = new Icon(item.Icon); } menu.Click += (sender, e) => { if (IsRun) { // MainProcess.Kill(); KillProcessAndChildren(MainProcess.Id); notifyIcon.Icon = StopIcon; IsRun = false; } }; return(menu); }
private ToolStripMenuItem Start(JsonMenuItem item) { var menu = new System.Windows.Forms.ToolStripMenuItem(); menu.Text = item.Text; if (!String.IsNullOrEmpty(item.Image)) { menu.Image = Bitmap.FromFile(item.Image); } else { menu.Image = StartImage; } if (!String.IsNullOrEmpty(item.Icon)) { StartIcon = new Icon(item.Icon); } RunCMD = item.CMD; menu.Click += (sender, e) => { if (!IsRun) { MainProcess.Start();//启动程序 MainProcess.StandardInput.WriteLine(RunCMD); MainProcess.StandardInput.AutoFlush = true; notifyIcon.Icon = StartIcon; IsRun = true; } }; return(menu); }
private ToolStripMenuItem Exit(JsonMenuItem item) { var menu = new System.Windows.Forms.ToolStripMenuItem(); var texts = item.Text.Split('|'); menu.Text = texts[0]; if (!String.IsNullOrEmpty(item.Image)) { menu.Image = Bitmap.FromFile(item.Image); } menu.Click += (sender, e) => { if (MessageBox.Show(texts[1], texts[0], MessageBoxButtons.YesNo) == DialogResult.Yes) { if (IsRun) { KillProcessAndChildren(MainProcess.Id); notifyIcon.Icon = StopIcon; IsRun = false; } Application.Exit(); } }; return(menu); }
private ToolStripMenuItem AutoRun(JsonMenuItem item) { AutoRunMenu = new System.Windows.Forms.ToolStripMenuItem(); AppKey = item.CMD; AutoRunMenu.Text = item.Text; AutoRunMenu.Image = OkImage; return(AutoRunMenu); }
private ToolStripMenuItem Show(JsonMenuItem item) { var menu = new System.Windows.Forms.ToolStripMenuItem(); menu.Text = item.Text; if (!String.IsNullOrEmpty(item.Image)) { menu.Image = Bitmap.FromFile(item.Image); } menu.Click += (sender, e) => { TempProcess.Start(); TempProcess.StandardInput.WriteLine(item.CMD); TempProcess.StandardInput.AutoFlush = true; TempProcess.StandardInput.WriteLine("exit"); TempProcess.Close(); InitProcess(out TempProcess); }; return(menu); }