uses RichEdit;
procedure Surligner(RichEdit: TRichEdit; Color: TColor);
var
Format: CHARFORMAT2;//Contient les informations de formatage d'un RichEdit.
begin
FillChar(Format, SizeOf(Format), 0);
Format.cbSize := SizeOf(Format);
Format.dwMask := CFM_BACKCOLOR;
Format.crBackColor := Color;
RichEdit.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));
RichEdit.SelStart := RichEdit.SelStart;//Pour éviter l'effet troublant de la sélection en négatif.
end;
{Utilisation.}
procedure TForm1.RichEdit1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Surligner(RichEdit1, clYellow);//Surligne les sélections en jaune.
end;