RichTextBox BeginUpdate () EndUpdate () Extension methods do not work

I have a richTextBox that I use to do syntax highlighting. This is a small editing tool, so I did not write a special syntax shortcut - instead, I use Regexand update when I detect input delay using the event handler for the event Application.Idle:

Application.Idle += new EventHandler(Application_Idle);

in the event handler, I check the time during which the text field has been inactive:

private void Application_Idle(object sender, EventArgs e)
{
    // Get time since last syntax update.
    double timeRtb1 = DateTime.Now.Subtract(_lastChangeRtb1).TotalMilliseconds;

   // If required highlight syntax.
   if (timeRtb1 > MINIMUM_UPDATE_DELAY)
   {
       HighlightSyntax(ref richTextBox1);
       _lastChangeRtb1 = DateTime.MaxValue;
   }
}

But even with relatively small glare, RichTextBoxit flickers very much and has no methods richTextBox.BeginUpdate()/EndUpdate(). To overcome this, I found this answer to a similar dilemma of Hans Passan (Hans Passant never let me down!):

using System; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 

class MyRichTextBox : RichTextBox 
{ 
    public void BeginUpdate() 
    { 
        SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)0, IntPtr.Zero); 
    }

    public void EndUpdate() 
    { 
        SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero);  
    } 

    [DllImport("user32.dll")] 
    private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp); 
    private const int WM_SETREDRAW = 0x0b; 
} 

; / (. ).

Odd Error Caused by RichTextBox Method Extension

, , , ?

.

+5
1

EndUpdate, Invalidate. , , :

public void EndUpdate() 
{ 
  SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero);  
  this.Invalidate();
}
+7

All Articles