开发者

RichTextBox and UserPaint

I'm trying to paint ov开发者_运维知识库er a RichTextBox but the only way I can do it is by calling OnPaint/OnPaintBackground.

The problem is the OnPaint or OnPaintBackground aren't called unless the "UserPaint" flag is on, but when this flag is on - the text itself won't be painted!

how can I solve this?


This is the code I use to ensure OnPaint is called after RichTextBox has handled the painting itself first:

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; }
    }


}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜