谢谢大家的回答。
由于似乎没有“正确”的方法来做到这一点,我设计了以下解决方案:
unit TRichEditRemoveSelectionBar;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
procedure RichEdit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure RichEdit1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
B: Boolean = False;
implementation
{$R *.dfm}
// ------------------------------------------------------------------------- //
procedure TForm1.RichEdit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (GetCursor <> Screen.Cursors[crDefault]) and
(GetCursor <> Screen.Cursors[crIBeam]) then
begin
SetCursor(Screen.Cursors[crIBeam]);
B := True;
end else
B := False;
end;
procedure TForm1.RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if B then
begin
SetCursor(Screen.Cursors[crIBeam]);
RichEdit1.SelLength := 0;
end;
end;
procedure TForm1.RichEdit1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if B then
SetCursor(Screen.Cursors[crIBeam]);
end;
// ------------------------------------------------------------------------- //
end.
它一点也不优雅,但它完成了工作。
请注意,此代码不允许双击整行选择,并且它不处理三次单击全文选择。为此,您可能必须使用拦截器类。