//如果想自己写的话就这样,要不然直接继承TWinControl 就有了
unit uTest;
interface
uses
Windows, Messages, Classes, Controls;
type
TmyObject = class(TComponent)
private
FOnEnter: TNotifyEvent ;
FOnExit: TNotifyEvent;
procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
protected
procedure DoEnter; dynamic;
procedure DoExit; dynamic;
published
property OnEnter: TNotifyEvent read FOnEnter write FOnEnter;
property OnExit: TNotifyEvent read FOnExit write FOnExit;
end;
procedure Register;
implementation
{ TmyObject }
procedure Register;
begin
RegisterComponents('Samples', [TmyObject]);
end;
procedure TmyObject.CMEnter(var Message: TCMEnter);
begin
DoEnter;
end;
procedure TmyObject.CMExit(var Message: TCMExit);
begin
DoExit;
end;
procedure TmyObject.DoEnter;
begin
if Assigned(FOnEnter) then FOnEnter(Self);
end;
procedure TmyObject.DoExit;
begin
if Assigned(FOnExit) then FOnExit(Self);
end;