这样就行了:
unit ExLabel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TExLabel = class(TLabel)
private
FOnMouseEnter: TNotifyEvent;
FOnMouseLeave: TNotifyEvent;
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
protected
{ Protected declarations }
public
{ Public declarations }
published
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TExLabel]);
end;
{ TExLabel }
procedure TExLabel.CMMouseEnter(var Msg: TMessage);
begin
if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
end;
procedure TExLabel.CMMouseLeave(var Msg: TMessage);
begin
if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;
end.