给你贴一段,见议你多多研究Vcl的源码:
unit Panel1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TPanelJC = class(TPanel)
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
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
published
property OnMouseEnter:TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave:TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DevTools', [TPanelJC]);
end;
{ TPanelJC }
procedure TPanelJC.CMMouseEnter(var Msg: TMessage);
begin
if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
inherited;
end;
procedure TPanelJC.CMMouseLeave(var Msg: TMessage);
begin
if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
inherited;
end;
constructor TPanelJC.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
destructor TPanelJC.Destroy;
begin
inherited Destroy;
end;
end.