给你个按钮的例子:
unit QButton1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TButton1 = class(TButton)
private FOnMouseLeave: TNotifyEvent;
procedure WZMouseLeave(var Msg:TMessage); message CM_MOUSELEAVE;
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TButton1]);
end;
procedure TButton1.WZMouseLeave(var Msg: TMessage);
begin
inherited;//继承父类
if csLButtonDown in ControlState then
begin
Self.MouseUp(mbLeft,[ssLeft],0,0);
end;
if Assigned (FonMouseLeave) then FOnMouseLeave(Self);
end;
end.