多彩多行 TMemo

9

在Delphi XE2中是否可以配置多彩多行TMemo?
当我编写以下代码时:

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  FirstVariable, SecondVariable, ThirdVariable :BOOL;
begin
  if FirstVariable then
    begin
      Memo1.Font.Color := clGreen;
      Memo1.Lines.Add('FirstVariable = True');
    end
  else if SecondVariable then
    begin
      Memo1.Font.Color := clBlue;
      Memo1.Lines.Add('SecondVariable = True');
    end
  else
    begin
      Memo1.Font.Color := clRed;
      Memo1.Lines.Add('ThirdVariable = True');
    end;
end;

根据变量条件,所有先前存在的行的字体颜色都会发生改变。


1
请移除 = true - Andreas Rejbrand
1个回答

21

不,这是不可能的。但是你可以使用一个RICHEDIT控件,例如TRichEdit封装器。

RichEdit1.SelAttributes.Color := clGreen;
RichEdit1.Lines.Add('First line.');

RichEdit1.SelAttributes.Color := clBlue;
RichEdit1.Lines.Add('Second line.');

RichEdit1.SelAttributes.Color := clRed;
RichEdit1.Lines.Add('Third line.');

2
我认为从技术上讲这是可能的(尚未尝试),通过直接绘制到画布上。然而,这远远超出了必要的范围,富文本编辑器就是为此而设计的。 - Jerry Dodge

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接