using System; using System.Drawing; using System.Windows.Forms; namespace ErpServer { public partial class MainForm { public void AppendLog(string msg) { AppendLog(msg, Color.Blue); } public void AppendLog(string msg, Color c) { AppendLog(txtCon, "", msg, c); } public void AppendLog(RichTextBox rtb, string tag, string msg, Color c) { try { string txt = getDateTime() + " " + msg + "\r\n"; if (this.IsHandleCreated) { this.Invoke(new MethodInvoker(delegate { //RemovePrevAppend(rtb); helper.AppendWithColor(rtb, txt, c); rtb.SelectionStart = rtb.TextLength; rtb.ScrollToCaret(); })); } else { //RemovePrevAppend(rtb); helper.AppendWithColor(rtb, txt, c); rtb.SelectionStart = rtb.TextLength; rtb.ScrollToCaret(); } //log4Helper.debug(msg); //writeAppend(tag, txt);//添加到本地目录 } catch (Exception ex) { helper.writeLog("添加RICHTEXTBOX内容时发生错误:" + ex.Message); } } public string getDateTime() { return "[" + DateTime.Now.ToString("HH:mm:ss") + "]"; } } }