比如tmemo控件中的内容是:你好,我好,大家好
现在要将大家好变成红色谢谢各位指导

解决方案 »

  1.   

    memo控件没法改变局部字体颜色的
    用richedit可以实现
    procedure TForm1.Button1Click(Sender: TObject);
    begin
        RichEdit1.SelAttributes.Color:=clblue;
    end;
      

  2.   

    其实是这样的,我有2个richedit,相互比对,不一致的用红色标出,这个动作应该是自动的,该怎么做
      

  3.   

    要么这样
    richedit的内容是:你好,我好,大家好
    procedure TForm1.FormShow(Sender: TObject);
    begin
    RichEdit1.SelStart:=12;
    RichEdit1.SelLength:=6;
    RichEdit1.SelAttributes.Color:=clred;
    RichEdit1.SelStart:=0;
    end;
    其中selstart可以根据程序动态调
      

  4.   

    未调试,else部分参考上面if部分
    procedure TForm1.Button1Click(Sender: TObject);
    var i,j:integer;
    begin
        if RichEdit1.Lines.Count>RichEdit2.Lines.Count then
        begin
            for i:=0 to RichEdit2.Lines.Count-1 do
            begin
                if length(RichEdit1.Lines.Strings[i])>length(RichEdit2.Lines.Strings[i]) then
                begin
                    for j:=0 to length(RichEdit2.Lines.Strings[i]) do
                    begin
                        if RichEdit1.Lines.Strings[i][j]<>RichEdit2.Lines.Strings[i][j] then
                        begin
                            RichEdit1.SelStart:=RichEdit1.CaretPos.Y+j;
                            RichEdit1.SelLength:=1;
                            RichEdit1.SelAttributes.Color:=clred;
                        end;
                        RichEdit1.SelStart:=RichEdit1.CaretPos.Y+j;
                        RichEdit1.SelLength:=length(RichEdit1.Lines.Strings[i])-j;
                        RichEdit1.SelAttributes.Color:=clred;
                    end;
                end
                else
                begin            end;
            end;
            for i:=i to RichEdit1.Lines.Count-1 do
            begin
                RichEdit1.SelStart:=RichEdit1.CaretPos.Y;
                RichEdit1.SelLength:=length(RichEdit1.Lines.Strings[i]);
                RichEdit1.SelAttributes.Color:=clred;
            end;
        end
        else
        begin    end;
    end;
      

  5.   

    真是很郁闷,richedit里好像只能找到“大家好”在第几行,而selstart是第几个字符,怎么都达不到想要的效果啊
      

  6.   

    ok,老大,现在你就教我怎么在richedit中找指定的字符串和该字符串的起始位置吧
      

  7.   

    找指定的字符串和该字符串的起始位置我一般都是用循环
    for i:=0 to RichEdit1.Lines.Count-1 do然后针对每一行查找
    用pos就可以
      

  8.   

    procedure TForm1.Button1Click(Sender: TObject);begin
      FindDialog1.Position := Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
      FindDialog1.Execute;
    end;procedure TForm1.FindDialog1Find(Sender: TObject);
    var
      FoundAt: LongInt;
      StartPos, ToEnd: Integer;
    begin
      with RichEdit1 do
      begin
        { begin the search after the current selection if there is one }
        { otherwise, begin at the start of the text }
        if SelLength <> 0 then      StartPos := SelStart + SelLength
        else      StartPos := 0;    { ToEnd is the length from StartPos to the end of the text in the rich edit control }    ToEnd := Length(Text) - StartPos;    FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
        if FoundAt <> -1 then
        begin
          SetFocus;
          SelStart := FoundAt;
          SelLength := Length(FindDialog1.FindText);
        end;
      end;
    end;