RichTextBoxEx.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.IO;
  6. using System.Drawing;
  7. using System.Drawing.Drawing2D;
  8. using System.ComponentModel;
  9. using System.Runtime.InteropServices;
  10. namespace LYFZ.ComponentLibrary
  11. {
  12. public class RichTextBoxEx : System.Windows.Forms.RichTextBox
  13. {
  14. public RichTextBoxEx() {
  15. }
  16. /// <summary>
  17. /// 添加指定颜色的文字到文本框对象
  18. /// </summary>
  19. /// <param name="text">要添加的文本</param>
  20. /// <param name="color">指定的颜色</param>
  21. public void AppendText(string text,Color color)
  22. {
  23. this.SelectionStart = this.TextLength;
  24. this.SelectionColor = color;
  25. this.AppendText(text);
  26. }
  27. /// <summary>
  28. /// 添加一行指定颜色的文字到文本框对象
  29. /// </summary>
  30. /// <param name="text">要添加的文本</param>
  31. /// <param name="color">指定的颜色</param>
  32. public void AppendLineText(string text, Color color)
  33. {
  34. if (this.TextLength > 0)
  35. this.AppendText("\r\n" + text, color);
  36. else
  37. this.AppendText(text, color);
  38. }
  39. }
  40. }