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?
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.