Stopping a RichTextBox updating

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kelvin.koogan@googlemail.com

    #1

    Stopping a RichTextBox updating

    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->SelectionSta rt = m->Index;
    pRichTextBox->SelectionLengt h = m->Length;
    pRichTextBox->SelectionCol or = SystemPens::Hig hlightText->Color;
    pRichTextBox->SelectionBackC olor = SystemPens::Hig hlight->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

  • Herfried K. Wagner [MVP]

    #2
    Re: Stopping a RichTextBox updating

    <kelvin.koogan@ googlemail.coms chrieb:
    >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->SelectionSta rt = m->Index;
    pRichTextBox->SelectionLengt h = m->Length;
    pRichTextBox->SelectionCol or = SystemPens::Hig hlightText->Color;
    pRichTextBox->SelectionBackC olor = SystemPens::Hig hlight->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/>

    Comment

    Working...