// 确切的说,在选中状态下是不应该丢失选中文本的。
// 比较全面的做法如下,按右键可以达到很好的你好的效果
procedure TForm1.RxRichEdit1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
var
TextRange: TCharRange;
atPos:Longint;
mousePoint:TPoint;
begin
if Button = mbRight then
begin
RxRichEdit1.Perform(EM_EXGETSEL,0, Longint(@TextRange));
if TextRange.cpMin<>TextRange.cpMax then
begin
mousePoint.x:=x;
mousePoint.y:=y;
atPos:=RxRichEdit1.Perform(EM_CHARFROMPOS,0,Longint(@mousePoint));
if ( atPos<TextRange.cpMin ) or (atPos>TextRange.cpMax) then
RxRichEdit1.Perform(WM_LBUTTONDOWN, MK_LBUTTON, MakeLong(X, Y));
end
else
RxRichEdit1.Perform(WM_LBUTTONDOWN, MK_LBUTTON, MakeLong(X, Y));
end;
end;