How do you prevent a RichTextBox from refreshing its display?

前端 未结 6 1320
再見小時候
再見小時候 2020-11-30 09:10

I have a RichTextBox where I need to update the Text property frequently, but when I do so the RichTextBox \"blinks\" annoyingly as it refreshes all throughout a method call

6条回答
  •  孤街浪徒
    2020-11-30 10:03

    Found here: http://bytes.com/forum/thread276845.html

    I ended up sending a WM_SETREDRAW via SendMessage to disable then reenable followed by an Invalidate() after I finished updating. That seemed to work.

    I've never tried this method. I have written an application with a RTB that has syntax highlighting and used the following in the RTB class:

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == paint)
        {
            if (!highlighting)
            {
                base.WndProc(ref m); // if we decided to paint this control, just call the RichTextBox WndProc
            }
            else
            {
                m.Result = IntPtr.Zero; // not painting, must set this to IntPtr.Zero if not painting otherwise serious problems.
            }
        }
        else
        {
            base.WndProc(ref m); // message other than paint, just do what you normally do.
        }
    }
    

    Hope this helps.

提交回复
热议问题