Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RichTextBox and UserPaint

I'm trying to paint over 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?

like image 247
Idov Avatar asked Jan 21 '23 11:01

Idov


1 Answers

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


}
like image 123
pgfearo Avatar answered Jan 28 '23 14:01

pgfearo