1

How can I make the first 4 characters in a line I am going to add bold?
Example:

richedit1.Lines.Add('Test123');

I want Test to be bold but leave 123 normal.

Can someone help me?

Jongware
  • 22,200
  • 8
  • 54
  • 100
jwz104
  • 337
  • 2
  • 10
  • 22
  • 7
    while the question is not an exact duplicate, the first answer to this question will give you exactly what you need: http://stackoverflow.com/questions/10645033/richedit-style-formatting-changes-on-its-own – Argalatyr Apr 19 '14 at 23:05

1 Answers1

1

Try something like this:

procedure TForm1.AddFormattedText(const AText: string; AStyle: TFontStyles);
begin
  RichEdit1.SelStart := RichEdit1.GetTextLen;
  RichEdit1.SelLength := 0;
  RichEdit1.SelAttributes.Style := AStyle;
  RichEdit1.SelText := AText;
end;

AddFormattedText('Test', [fsBold]);
AddFormattedText('123'+sLineBreak, []);
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770