挺急。

解决方案 »

  1.   

    先确定选择区域,然后
    RichEdit1.SelAttributes.Color := clBlue;
      

  2.   

    选择区域的确定
    需要配合FindDialog
    利用RichEdit的
    SelStart
    SelLength
    方法
      

  3.   

    我的代码:
    void __fastcall SetLineFont(int chgtyp,int linenum,TRichEdit *redt)
    {
      int row =0,len=0;
      AnsiString tmpstr;  row = linenum;  for(int i=0;i<row;i++)
      {
        tmpstr = redt->Lines->Strings[i];
        len = len + tmpstr.Length();
      }  redt->HideSelection = true;
      redt->SelStart = len; //2*row;
      tmpstr = redt->Lines->Strings[row];
      redt->SelLength = tmpstr.Length();
      //redt->SelAttributes->Height +=5;  switch(chgtyp)
      {
        case 1: redt->SelAttributes->Color = clBlue; //添加
                 break;
        case 2: redt->SelAttributes->Color = clRed; //删除
                break;
        case 3: redt->SelAttributes->Color = clTeal; //改变
                break;
        default:redt->SelAttributes->Color = clBlack;
                break;
      }
    }但有时调用时,不准确,比如我在RichEdit中加入UNix文本,然后设置颜色时,不准确,怎么办?
      

  4.   

    自定义函数如下:function CurrText: TTextAttributes;
    实现:
    function TMainForm.CurrText: TTextAttributes;
    begin
      if richedit1.SelLength > 0 then Result := richedit1.SelAttributes
      else Result := richedit1.DefAttributes;
    end;procedure button1.click(sender: TObject);
    begin
      currtext.color := 颜色值;
    end;