如何改变RICHEDIT中的某一行文字的颜色?

解决方案 »

  1.   

    usesRichEdit;procedure RE_SetSelBgColor(RichEdit: TRichEdit; AColor: TColor);varFormat: CHARFORMAT2;beginFillChar(Format, SizeOf(Format), 0);with Format dobegincbSize := SizeOf(Format);dwMask := CFM_BACKCOLOR;crBackColor := AColor;Richedit.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));end;end;// Example: Set clYellow background color for the selected text.procedure TForm1.Button1Click(Sender: TObject);beginRE_SetSelBgColor(RichEdit1, clYellow);end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      N: Integer;
    begin
      N := 3; //从0开始
      RichEdit1.CaretPos := Point(RichEdit1.CaretPos.X, N); //将光标起始位置设置到N行
      RichEdit1.SelLength := Length(RichEdit1.Lines[N]); //选择的长度为N行的字符数  RichEdit1.SelAttributes.Color := clRed; //操作选择区域的属性
    end;
      

  3.   

    RichEdit1.CaretPos := Point(0, N); //修改一下
      

  4.   

    谢谢
            zswangII(伴水清清)(一贴不灌,何以灌天下?)