TRichEdit中同一行中的彩色文本 [英] Colorful text in the same line in TRichEdit

查看:192
本文介绍了TRichEdit中同一行中的彩色文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在同一行中写不同颜色的文本? (我使用richedit).

How to write text in the same line but with different color? (I use 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:

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;

这会产生

这篇关于TRichEdit中同一行中的彩色文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆