Stopping a RichTextBox updating

  • Thread starter Thread starter kelvin.koogan
  • Start date Start date
K

kelvin.koogan

I am trying to do an operation where I find and highlight all
instances of a string in a RichTextBox. E.g.

pMatchesFound = Regex::Matches(pRichTextBox->Text, pStr, options);

for (int i = 0; i < pMatchesFound->Count; i++)
{
Match ^m = pMatchesFound;

pRichTextBox->SelectionStart = m->Index;
pRichTextBox->SelectionLength = m->Length;
pRichTextBox->SelectionColor = SystemPens::HighlightText->Color;
pRichTextBox->SelectionBackColor = SystemPens::Highlight->Color;
}

However the user sees the text scrolling through the RichTextBox as
all the strings are highlighted, which isn't what I want. I've tried
to prevent this with SuspendLayout but it doesn't work.

Is there a way to stop the RichTextBox updating while I'm highlighting
all the strings?

TIA,
KK
 
I am trying to do an operation where I find and highlight all
instances of a string in a RichTextBox. E.g.

pMatchesFound = Regex::Matches(pRichTextBox->Text, pStr, options);

for (int i = 0; i < pMatchesFound->Count; i++)
{
Match ^m = pMatchesFound;

pRichTextBox->SelectionStart = m->Index;
pRichTextBox->SelectionLength = m->Length;
pRichTextBox->SelectionColor = SystemPens::HighlightText->Color;
pRichTextBox->SelectionBackColor = SystemPens::Highlight->Color;
}

However the user sees the text scrolling through the RichTextBox as
all the strings are highlighted, which isn't what I want. I've tried
to prevent this with SuspendLayout but it doesn't work.

Is there a way to stop the RichTextBox updating while I'm highlighting
all the strings?


You could use the 'SendMessage' function (exported by "user32.dll") together
with 'WM_SETREDRAW' to disable/enable redrawing of the window.
 
Back
Top