1

I am working with a RichEdit and I am adding lines to it, containing various colors. Now I use this approach:

LogRichEdit.Lines.Add(someText);
...
LogRichEdit.SelStart:=res+8;
LogRichEdit.SelLength:=4;
LogRichEdit.SelAttributes.Color:=clSilver;

where res is a position of the text to format. Nevermind that. The problem I have is that when I add this line and then edit it, it flickers (by selecting and deselecting the text). How can I work with it in a nicer way? I thought I could have a rtf-string variable of some sort, do my things with it and then .add it to the RichEdit. Or?

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Martin Melka
  • 7,177
  • 16
  • 79
  • 138

1 Answers1

3

You should be able to avoid the flickering by using BeginUpdate/EndUpdate.

RichEdit.Lines.BeginUpdate;
try
  // make modifications to RichEdit.Lines
finally
  RichEdit.Lines.EndUpdate;
end;

The call to BeginUpdate suppresses UI updates until EndUpdate is called.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490