RichTextBox和UserPaint

Ido*_*dov 4 c# richtextbox winforms

我正在尝试绘制RichTextBox,但我能做到的唯一方法是通过调用OnPaint/OnPaintBackground.

问题是除非"UserPaint"标志打开,否则不会调用OnPaint或OnPaintBackground,但是当此标志打开时 - 文本本身不会被绘制!

我该怎么解决这个问题?

pgf*_*aro 8

这是我用来确保在RichTextBox首先处理绘画本身后调用OnPaint的代码:

class MyRichTextBox: RichTextBox
{
    private const int WM_PAINT = 15;
    protected override void WndProc(ref System.Windows.Forms.Message m)
    {
       base.WndProc (ref m);
       if (m.Msg == WM_PAINT && !inhibitPaint)
       {
           // raise the paint event
           using (Graphics graphic = base.CreateGraphics())
               OnPaint(new PaintEventArgs(graphic,
                base.ClientRectangle));
       }

   }

    private bool inhibitPaint = false;

    public bool InhibitPaint
    {
        set { inhibitPaint = value; }
    }


}
Run Code Online (Sandbox Code Playgroud)