绘制RichTextBox

Dem*_*sch 6 c# richtextbox winforms

我正在尝试在RichTextBox中绘制单词和段落的边框,但是当我打开UserPaint时,它不再绘制文本,而我的自定义绘画似乎有效.可能我只是忘了打开别的东西?这就是我所拥有的

public partial class RichTextBoxEx : RichTextBox
{
    public RichTextBoxEx()
    {
        InitializeComponent();
        SetStyle(ControlStyles.UserPaint, true);
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        //Do some painting here
    }
}
Run Code Online (Sandbox Code Playgroud)

使用这个问题的信息对我没有帮助

Lar*_*ech 7

这对我有用:

class RichBox : RichTextBox {
  private const int WM_PAINT = 15;

  protected override void WndProc(ref Message m) {
    if (m.Msg == WM_PAINT) {
      this.Invalidate();
      base.WndProc(ref m);
      using (Graphics g = Graphics.FromHwnd(this.Handle)) {
        g.DrawLine(Pens.Red, Point.Empty, 
                   new Point(this.ClientSize.Width - 1,
                             this.ClientSize.Height - 1));
      }
    } else {
      base.WndProc(ref m);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)