Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7548787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:47:15+00:00 2026-05-30T09:47:15+00:00

I have a richTextBox I am using to perform some syntax highlighting. This is

  • 0

I have a richTextBox I am using to perform some syntax highlighting. This is a small editing facility so I have not written a custom syntax highlighter – instead I am using Regexs and updating upon the detection of an input delay using an event handler for the Application.Idle event:

Application.Idle += new EventHandler(Application_Idle);

in the event handler I check for the time the text box 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 for relatively small highlights the RichTextBox flickers heavily and it has no richTextBox.BeginUpdate()/EndUpdate() methods. To overcome this I found this answer to a similar dilemma by Hans Passant (Hans Passant has 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; 
} 

However, this gives me odd behaviour upon an update; the cursor dies/freezes and shows nothing but odd looking stripes (see image below).

Odd Error Caused by RichTextBox Method Extension

I clearly can’t use an alternative thread to update the UI, so what am I doing wrong here?

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:47:16+00:00Added an answer on May 30, 2026 at 9:47 am

    Try modifying the EndUpdate to also call Invalidate afterwards. The control doesn’t know it needs to do some updating, so you need to tell it:

    public void EndUpdate() 
    { 
      SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero);  
      this.Invalidate();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Silverlight application using the RichTextBox as a rich text editor for
I am developing an app using WinForms and the RichTextBox control. This control allows
I'm using .NET 3.5 I have a FlowDocument inside a FlowDocumentScrollViewer. I am not
I have developed a small chat client using WPF. In each chat window, it
How can I syntax highlight using the scintilla. I have no idea how to
I have a richtextbox (WPF extended toolkit) that I am using in my WPF
Probably not double buffering but I'm trying to make a highlighter (pure amusement) using
How to get the MouseOver text in a RichTextBox . I have tried using
HI, I am developing an editor using RichTextBox in WPF, i have to implement
I am using WPF and have a Table inside a RichTextBox control. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.