RichTextBoxEx.cs 825 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. namespace HTEXMark
  9. {
  10. public class RichTextBoxEx : RichTextBox
  11. {
  12. public string PlaceHolder { get; set; }
  13. protected override void WndProc(ref Message m)
  14. {
  15. base.WndProc(ref m);
  16. if (m.Msg == 0xF || m.Msg == 0x133)
  17. {
  18. WmPaint(ref m);
  19. }
  20. }
  21. private void WmPaint(ref Message m)
  22. {
  23. Graphics g = Graphics.FromHwnd(base.Handle);
  24. if (!String.IsNullOrEmpty(this.PlaceHolder) && string.IsNullOrEmpty(this.Text))
  25. g.DrawString(this.PlaceHolder, this.Font, new SolidBrush(Color.LightGray), 0, 0);
  26. }
  27. }
  28. }