要求使用程序编码的方式,在rxRichEdit/richEdit中加入文字,但又要求加入的文字能够自由的设置字体、字体颜色等,(加入一行文字,这行文字可能与以前加入的颜色不一致,也可能这一行文字的前面和后面的颜色又不相同)。谢谢!

解决方案 »

  1.   

    设置richEdit的SelAttributes就可以达到你的要求
      

  2.   

    procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if Key = #13 then
      begin
        Richedit1.SelAttributes.Color := RGB(Random(255), Random(255),Random(255));
      end;
    end;
      

  3.   

    with RichEdit1.SelAttributes do
      begin
        Color := clRed;
        Height := Height + 5;
      end;
      RichEdit1.Lines.Add('This line of text will be red.');
      

  4.   

    如果同一行出现不同的字体颜色呢,
    lines.add是加入一行,而加入的这一行的字体、颜色是一样的啊
    我要不一样~即加入的一行有2种或者2种以上的颜色
      

  5.   

    一样啊,还是用这个,可以看看delphi帮助
    with RichEdit1.SelAttributes do
      begin
        Color := clRed;
        Height := Height + 5;
      end;
      RichEdit1.SelText := 'This line of';
    with RichEdit1.SelAttributes do
      begin
        Color := clGreen;
        Style := [fsBold];
      end;
      RichEdit1.SelText := ' text will be red.';