public void Init( ) { int index = 0; TabSettings.LoadSettings(TabFileName, (tab) => { AddProcess(tab).Index = index++; }); ColorSettings.LoadColorTable("color.json"); }
void PaintTabControl() { tabMain.DrawMode = TabDrawMode.OwnerDrawFixed; tabMain.DrawItem += (sender, e) => { var model = SafeGetModel(tabMain.TabPages[e.Index]); Rectangle myTabRect = tabMain.GetTabRect(e.Index); Brush textBrush = null; Brush bgBrush = null; if (model.Running) { bgBrush = ColorSettings.ColorToBrush(Color.Green); textBrush = ColorSettings.ColorToBrush(Color.White); } else if (model.SelfExit) { bgBrush = ColorSettings.ColorToBrush(Color.Red); textBrush = ColorSettings.ColorToBrush(Color.White); } if (e.Index == tabMain.SelectedIndex) { textBrush = ColorSettings.ColorToBrush(Color.White); bgBrush = ColorSettings.ColorToBrush(Color.Black); } else if (textBrush == null) { textBrush = ColorSettings.ColorToBrush(Color.Black); } if (bgBrush != null) { e.Graphics.FillRectangle(bgBrush, myTabRect); } //先添加TabPage属性 e.Graphics.DrawString(tabMain.TabPages[e.Index].Text, this.Font, textBrush, myTabRect.X + 2, myTabRect.Y + 2); }; }
public void Start() { if (Running) { return; } _manualStop = false; Running = true; var info = new ProcessStartInfo(FileName); info.Arguments = Args; info.RedirectStandardOutput = true; info.RedirectStandardError = true; info.RedirectStandardInput = true; info.StandardErrorEncoding = Encoding.UTF8; info.StandardOutputEncoding = Encoding.UTF8; info.UseShellExecute = false; info.CreateNoWindow = true; if (string.IsNullOrEmpty(WorkDir)) { info.WorkingDirectory = Path.GetDirectoryName(FileName); } else { info.WorkingDirectory = WorkDir; } ThreadPool.QueueUserWorkItem(delegate(object state) { SafeCall(delegate { if (OnStart != null) { OnStart(this); } }); Process p = null; try { p = Process.Start(info); _process = p; } catch (Exception e) { SafeCall(delegate { OnError(this, Color.Red, e.ToString()); }); } if (p != null) { p.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { if (e.Data == null) { return; } var c = ColorSettings.PickColorFromText(e.Data); SafeCall(delegate { WriteLog(c, e.Data); }); }; p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) { if (e.Data == null) { return; } var c = ColorSettings.PickColorFromText(e.Data); SafeCall(delegate { WriteLog(c, e.Data); }); }; p.BeginOutputReadLine(); p.BeginErrorReadLine(); Application.DoEvents(); p.WaitForExit(); ExitCode = p.ExitCode; p.Close(); } SafeCall(delegate { if (!_manualStop) { SelfExit = true; } if (OnExit != null) { OnExit(this); } }); _process = null; Running = false; }); }