Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Different color in a line for TRichEdit

357 views
Skip to first unread message

sam

unread,
Apr 21, 2003, 11:46:00 PM4/21/03
to

Hi,
I would like to know how to set the different color on a line
for TRichEdit. For example, I have a line with ' date, time,
message'. I want to have Date & time with one color, and Message
with another color in the same line. Is it possible to do it?
Thanks for help.

sam

Angus Johnson

unread,
Apr 22, 2003, 1:38:23 AM4/22/03
to
Sam,

It's not possible to have more than one background color using either a
TMemo or TRichedit control. However, you can use multiple font colors in a
TRichedit control. If you want to multiple background colors you'll have to
look at numerous third party components which do this.


"sam" <samue...@hotmail.com> wrote in message
news:3ea4baf8$1...@newsgroups.borland.com...

Peter Below (TeamB)

unread,
Apr 22, 2003, 1:42:52 PM4/22/03
to

Yes. The easiest way is to manipulate the color (of the font) as you
add the text items. For this you do not use the Lines property, you use
SelStart, SelAttributes, and SelText.

// set caret to end of text
richedit.SelStart := richedit.GetTextLen;

richedit.selattributes.color := datacolor;
richedit.seltext := dateAndTime;
richedit.selattributes.color := messagecolor;
richedit.seltext : messagestring + #13#10;
...next line

As long as the SelLength is 0 (setting SelStart sets it to 0) any
change to SelAttributes will apply to the text you next add with
SelText. Each assignment to SelText puts the SelStart at the end of the
inserted text, so you can just add more without having to set SelStart
manually again. The #13#10 starts a new line.

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


0 new messages