以下是我初学写组件时写的一个组件,添加了鼠标移入移出事件。
unit NewSpeedButton;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Buttons;
type
TNewSpeedButton = class(TSpeedButton)
private
FOnMouseEnter : TNotifyEvent;
FOnMouseLeave : TNotifyEvent;
protected
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
public
constructor Create(AOwner: TComponent);override;
published
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;
procedure Register;
implementation
constructor TNewSpeedButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
procedure TNewSpeedButton.CMMouseEnter(var Message: TMessage);//message CM_MOUSEENTER;
begin
inherited;
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;
procedure TNewSpeedButton.CMMouseLeave(var Message: TMessage);// message CM_MOUSELEAVE;
begin
inherited;
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;
procedure Register;
begin
RegisterComponents('dwh', [TNewSpeedButton]);
end;
end.