procedure TForm1.Button5Click(Sender: TObject);
var
Fmt :TCharFormat2;
begin
Fmt.cbSize := SizeOf(Fmt);
Fmt.dwMask := CFM_COLOR or CFM_BACKCOLOR or CFM_Weight;//告诉系统只有字体颜色和背景颜色两个字段的值有效
Fmt.crTextColor := clwhite;
Fmt.crBackColor := clred;//设置背景色
//fmt.wWeight :=0;
RichEdit1.Perform(EM_SETCHARFORMAT,SCF_SELECTION,integer(@Fmt));//发EM_SETCHARFORMAT消息给RichEdit
end;