Colorful text in the same line in TRichEdit
if you are using themes... answer above won't work..
you cannot see any colors...
till you remove seFont from styles..
RichEdit1.styleElements:=richedit1.styleElements-[seFont];
eg.
....
amsg:='Hola';
RichEdit1.SelStart := Length(RichEdit1.Lines.Text);
RichEdit1.SelAttributes.Color := acolor;
RichEdit1.Lines.Add(amsg + sLineBreak);
RichEdit1.SelLength := Length(amsg + sLineBreak);
You're on the right track. Just change SelAttributes
and use SelText
instead of Lines.Add
:
procedure TForm4.FormCreate(Sender: TObject);
begin
RichEdit1.Clear;
RichEdit1.SelAttributes.Color := clBlue;
RichEdit1.SelAttributes.Style := [fsBold];
RichEdit1.SelText := 'This is bold blue text.';
RichEdit1.SelAttributes.Color := clRed;
RichEdit1.SelAttributes.Style := [fsItalic];
RichEdit1.SelText := #32'This is italic red text';
end;
This produces