public void setlogRed(string s) { if (process.InvokeRequired) { DSetLog sl = new DSetLog(delegate(string text) { process.AppendText(DateTime.Now.ToString() + " " + text + Environment.NewLine); int i = process.Text.LastIndexOf("\n", process.Text.Length - 2); if (i > 1) { process.Select(i, process.Text.Length); process.SelectionColor = Color.Red; process.Select(i, process.Text.Length); process.SelectionFont = new Font(Font, FontStyle.Bold); } }); process.Invoke(sl, s); } else { log.AppendText(DateTime.Now.ToString() + " " + s + Environment.NewLine); int i = log.Text.LastIndexOf("\n", log.Text.Length - 2); if (i > 1) { log.Select(i, log.Text.Length); log.SelectionColor = Color.Red; log.Select(i, log.Text.Length); log.SelectionFont = new Font(Font, FontStyle.Bold); } } }
public void setlog(string s) { if (process.InvokeRequired) { // 实例一个委托,匿名方法, DSetLog sl = new DSetLog(delegate(string text) { process.AppendText(DateTime.Now.ToString() + " " + text + Environment.NewLine); }); // 把调用权交给创建控件的线程,带上参数 process.Invoke(sl, s); } else { process.AppendText(DateTime.Now.ToString() + " " + s + Environment.NewLine); } }