Stopping a RichTextBox updating

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
 
H

Herfried K. Wagner [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top