给你一个例子(给TSpeedButton添加OnMouseEnter和OnMouseLeave事件)
unit EnhSpeedButton;
interface
uses
; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
; Buttons;
type
; TEnhSpeedButton = class(TSpeedButton)
; private
; ; FOnMouseEnter: TNotifyEvent; //Make the Mouse Enter and Leave available
; ; FOnMouseLeave: TNotifyEvent;
; ; procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
; ; procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
; ; { Private declarations }
; protected
; ; { Protected declarations }
; public
; ; procedure Click; override;
; ; { Public declarations }
; published
; ; property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter; //These show up in events
; ; property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
; ; { Published declarations }
; end;
procedure Register;
implementation
procedure Register;
begin
; RegisterComponents('Samples', [TEnhSpeedButton]);
end;
{ TEnhSpeedButton }
procedure TEnhSpeedButton.CMMouseEnter(var Message: TMessage);
begin
; inherited;
; if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
end;
procedure TEnhSpeedButton.CMMouseLeave(var Message: TMessage);
begin
; inherited;
; if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;
end.
够简单吧。