سؤال

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?

هل كانت مفيدة؟

المحلول

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, []);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top