1) Select the text with the SelStart, SelLength properties.
2) Set the text attribtutes through the SelAttributes property.
>
<
1. Example/ Beispiel:
Add a colored line to a TRichEdit:
>
procedure AddColoredLine(ARichEdit: TRichEdit; AText: string ; AColor: TColor );
begin
with ARichEdit do
begin
SelStart := Length (Text);
SelAttributes.Color := AColor;
SelAttributes.Size := 8 ;
SelAttributes.Name := ‘MS Sans Serif’ ;
Lines.Add(AText);
end ;
end ;
procedure TForm1.Button1Click(Sender: TObject );
begin
AddColoredLine(RichEdit1, ‘Hallo’ , clRed);
AddColoredLine(RichEdit1, ‘Hallo’ , clGreen);
end ;
<
2. Example/ Beispiel:
To color the 5 characters.
Die ersten 5 Zeichen im Richedit blau einfдrben.
>
procedure TForm1.Button1Click(Sender: TObject );
begin
RichEdit1.SelStart := 0 ;
RichEdit1.SelLength := 5 ;
RichEdit1.SelAttributes.Color := clBlue;
end ;
To color a specified line with a color
So kann eine beliebige Zeile mit einer Farbe gefдrbt werden:
>