Hier noch eine andere Möglichkeit, das Caret zu verstecken. Dabei läßt sich, im Gegensatz zur oben gezeigten Methode, Text weiterhin markieren.
Delphi-Quellcode:
unit MyRichEdit;
interface
uses
SysUtils, Classes, Controls, StdCtrls, ComCtrls, Messages;
type
TMyRichEdit =
class(TRichEdit)
private
FShowCaret: Boolean;
procedure SetShowCaret(
const Value: boolean);
procedure WMPaint(
var Message: TWMPaint);
message WM_PAINT;
procedure WMLButtonDown(
var Message: TWMLButtonDown);
message WM_LButtonDown;
procedure WMKeyDown(
var Message: TWMKeyDown);
message WM_KeyDown;
procedure HideTheCaret;
protected
public
constructor Create(AOwner: TComponent);
override;
published
property ShowCaret: Boolean
read FShowCaret
write SetShowCaret;
end;
procedure Register;
implementation
uses Windows;
procedure Register;
begin
RegisterComponents('
Samples', [TMyRichEdit]);
end;
{ TMyRichEdit }
procedure TMyRichEdit.HideTheCaret;
begin
if not FShowCaret
then
CreateCaret(
Handle, 0, 0, 0);
end;
constructor TMyRichEdit.Create(AOwner: TComponent);
begin
inherited;
FShowCaret := False;
end;
procedure TMyRichEdit.SetShowCaret(
const Value: boolean);
begin
FShowCaret := Value;
end;
procedure TMyRichEdit.WMKeyDown(
var Message: TWMKeyDown);
begin
inherited;
if Assigned(Parent)
then
HideTheCaret;
end;
procedure TMyRichEdit.WMLButtonDown(
var Message: TWMLButtonDown);
begin
inherited;
if Assigned(Parent)
then
HideTheCaret;
end;
procedure TMyRichEdit.WMPaint(
var Message: TWMPaint);
begin
inherited;
if Assigned(Parent)
then
HideTheCaret;
end;