[英]Colorful text in the same line in TRichEdit
如何在同一行中寫入不同顏色的文本? (我使用richedit)。
procedure TForm1.btnEClick(sender: TObject);
begin
m0.SelAttributes.Color := clBlue;
m0.SelAttributes.Style := [fsBold];
m0.lines.add('This is blue and it is bold');
m0.SelAttributes.Color := clGreen;
m0.SelAttributes.Style := [fsBold];
m0.lines.add ('This is Green and it is bold');
m0.lines.add('');
m0.lines.add('But how to write text in the same line with different color?');
// i want to have both blue and green in the same line
end;
最好的祝福,蜜蜂
你在正確的軌道上。 只需更改SelAttributes
並使用SelText
而不是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;
這產生
如果您正在使用主題......上面的答案將不起作用..
你看不到任何顏色......直到你從樣式中刪除 seFont ......
RichEdit1.styleElements:=richedit1.styleElements-[seFont];
例如。
....
amsg:='Hola';
RichEdit1.SelStart := Length(RichEdit1.Lines.Text);
RichEdit1.SelAttributes.Color := acolor;
RichEdit1.Lines.Add(amsg + sLineBreak);
RichEdit1.SelLength := Length(amsg + sLineBreak);
對於行中的最后一段文本,包括回車以結束該行。
RichEdit1.SelAttributes.Color := clGreen;
RichEdit1.SelAttributes.Style := [];
RichEdit1.SelText := 'This is the last piece of text on the line.' + #13;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.