MainForm.append.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace ErpServer
  5. {
  6. public partial class MainForm
  7. {
  8. public void AppendLog(string msg)
  9. {
  10. AppendLog(msg, Color.Blue);
  11. }
  12. public void AppendLog(string msg, Color c)
  13. {
  14. AppendLog(txtCon, "", msg, c);
  15. }
  16. public void AppendLog(RichTextBox rtb, string tag, string msg, Color c)
  17. {
  18. try
  19. {
  20. string txt = getDateTime() + " " + msg + "\r\n";
  21. if (this.IsHandleCreated)
  22. {
  23. this.Invoke(new MethodInvoker(delegate
  24. {
  25. //RemovePrevAppend(rtb);
  26. helper.AppendWithColor(rtb, txt, c);
  27. rtb.SelectionStart = rtb.TextLength;
  28. rtb.ScrollToCaret();
  29. }));
  30. }
  31. else
  32. {
  33. //RemovePrevAppend(rtb);
  34. helper.AppendWithColor(rtb, txt, c);
  35. rtb.SelectionStart = rtb.TextLength;
  36. rtb.ScrollToCaret();
  37. }
  38. //log4Helper.debug(msg);
  39. //writeAppend(tag, txt);//添加到本地目录
  40. }
  41. catch (Exception ex)
  42. {
  43. helper.writeLog("添加RICHTEXTBOX内容时发生错误:" + ex.Message);
  44. }
  45. }
  46. public string getDateTime()
  47. {
  48. return "[" + DateTime.Now.ToString("HH:mm:ss") + "]";
  49. }
  50. }
  51. }