Fons.
Set the SelAttributes property, then enter your text. From the Delphi 7
help:
with RichEdit1.SelAttributes do
begin
Color := clRed;
Height := Height + 5;
end;
RichEdit1.Lines.Add('This line of text will be red.');
Cheers,
Nicholas Sherlock
If you first run:
RichEdit.Lines.Clear;
RichEdit.SelAttributes.Color := clBlack;
RichEdit.Lines.Add('AAABBB');
RichEdit.SelStart := Length(RichEdit.Text) - 5;
RichEdit.SelLength := 3;
RichEdit.SelAttributes.Color := clRed;
RichEdit.SelStart := 0;
RichEdit.SelLength := 0;
you do have AAA in black and BBB in red in the same line. If after this
you run:
RichEdit.Lines.Add('CCC');
BBB will still be red. But:
RichEdit.Lines[0] := RichEdit.Lines[0] + 'CCC';
will change BBB to black.
> Cheers,
> Nicholas Sherlock
Thanks,
Fons.
> RichEdit.Lines.Add('CCC');
>
> BBB will still be red. But:
>
> RichEdit.Lines[0] := RichEdit.Lines[0] + 'CCC';
>
> will change BBB to black.
Try to change the selection instead, SetSelText or the like.
Replacing the entire text of a line, as you do, most probably must
result in a loss of all previous formatting. There exists no reason why
the control should retain text attributes, when a entire line is replaced.
DoDi
if you read the doc's on the DefAttributes in the help file, "at least
on mine", it leads you to believe that when you change the defattributes
and text that is added from that point uses the new defaults just
applied and does not effect existing text..
that is how I read it, if that is how it really works then good how
ever, if not, then the help is confusing.
from an old copy of delphi.
Description
Use DefAttributes to discover or set the default font characteristics
that the rich edit control uses for newly inserted text. These are the
characteristics of the text before any special attributes have been
applied. Once any special attributes are applied to a portion of text,
no text from that point on is considered to have the default attributes,
even if the attributes match the DefAttributes.
--
"I'd rather have a bottle in front of me than a frontal lobotomy"
http://webpages.charter.net/jamie_5
>>> RichEdit.Lines.Add('CCC');
>>>
>>> BBB will still be red. But:
>>>
>>> RichEdit.Lines[0] := RichEdit.Lines[0] + 'CCC';
>>>
>>> will change BBB to black.
>>
>>
>>
>> Try to change the selection instead, SetSelText or the like.
>>
>> Replacing the entire text of a line, as you do, most probably must
>> result in a loss of all previous formatting. There exists no reason
>> why the control should retain text attributes, when a entire line is
>> replaced.
>>
>> DoDi
>
> if you read the doc's on the DefAttributes in the help file, "at least
> on mine", it leads you to believe that when you change the defattributes
> and text that is added from that point uses the new defaults just
> applied and does not effect existing text..
Adding text and adding/changing lines may work very differently. I'd use
nothing but the Selection (SelStart, SelLength and SelText) for
updating, since these operations are known as supported by the
underlying (Windows RichEdit) control.
> from an old copy of delphi.
> Description
>
> Use DefAttributes to discover or set the default font characteristics
> that the rich edit control uses for newly inserted text. These are the
> characteristics of the text before any special attributes have been
> applied. Once any special attributes are applied to a portion of text,
> no text from that point on is considered to have the default attributes,
> even if the attributes match the DefAttributes.
AFAIK the RichEdit control organizes the text in *paragraphs*, not in
lines. That's the only useful internal representation for wrappable
text. Then all text, added to the end of the existing text, inherits the
paragraph attributes from the last/preceding paragraph.
Reading a line is okay, this will return the line as formatted
(wrapped...) for the actual window. But replacing a line will either
replace the portion of the paragraph with the new text, wrapping the
paragraph again as appropriate, or it will insert the changed line as a
paragraph of it's own, depending on explicit EOL characters occuring in
the added text.
I'd suggest to forget about the Lines property of the TRichEdit control,
and only work with the selected text.
DoDi
What I do now is adding/changing the text and saving the positions of
the characters I want to be colored differently and then do all the
coloring in one run.
I wanted some coloring. But in RTF you cannot change the background color ?
Fons.