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[i];

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

Re: Stopping a RichTextBox updating by Herfried

Herfried
Mon Mar 10 15:48:55 CDT 2008

<kelvin.koogan@googlemail.com> schrieb:
>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[i];
>
> 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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>