Procedure TForm1.FormCreate(Sender: TObject);
Begin
RichEdit1.Text := '012345678';
End;
Procedure TForm1.Button1Click(Sender: TObject);
Begin
RichEdit1.SelStart := 0;
RichEdit1.SelLength := 3;
RichEdit1.SelAttributes.Color := clRed; //012为红色
RichEdit1.SelStart := 5;
RichEdit1.SelLength := 4;
RichEdit1.SelAttributes.Color := clBlue; //5678为蓝色
//RichEdit1.ClearSelection;
//只是删除最后一个选区(如上面为蓝色的选区)的字符,不是清除 所有选择样式
End;
Procedure TForm1.Button2Click(Sender: TObject);
Begin
RichEdit1.SelStart := 0; //清除 所有选择样式
RichEdit1.SelLength := Length(RichEdit1.Text);
RichEdit1.SelAttributes.Color := clBlack;
End;