A
ahxia
Unregistered / Unconfirmed
GUEST, unregistred user!
因为读 MD 6有感,学做了一个感知MouseLeave,MouseEnter事件的button,
请大侠们指正一下。(好像简单的不应该会有错误了 。。。
unit myButton;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;
type
TmyButton = class(TButton)
private
fMouseEnter: TNotifyEvent;
fMouseLeave: TNotifyEvent;
protected
procedure cmMouseLeave(var msg: TMessage); message cm_MouseLeave;
procedure cmMouseEnter(var msg: TMessage); message cm_MouseEnter;
public
{ Public declarations }
published
property OnMouseEnter: TNotifyEvent read fMouseEnter write fMouseEnter;
property OnMouseLeave: TNotifyEvent read fMouseLeave write fMouseLeave;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('my', [TmyButton]);
end;
{ TmyButton }
procedure TmyButton.cmMouseEnter(var msg: TMessage);
begin
if Assigned(fMouseEnter) then
fMouseEnter(self);
end;
procedure TmyButton.cmMouseLeave(var msg: TMessage);
begin
if Assigned(fMouseLeave) then
fMouseLeave(self);
end;
end.
请大侠们指正一下。(好像简单的不应该会有错误了 。。。
unit myButton;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;
type
TmyButton = class(TButton)
private
fMouseEnter: TNotifyEvent;
fMouseLeave: TNotifyEvent;
protected
procedure cmMouseLeave(var msg: TMessage); message cm_MouseLeave;
procedure cmMouseEnter(var msg: TMessage); message cm_MouseEnter;
public
{ Public declarations }
published
property OnMouseEnter: TNotifyEvent read fMouseEnter write fMouseEnter;
property OnMouseLeave: TNotifyEvent read fMouseLeave write fMouseLeave;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('my', [TmyButton]);
end;
{ TmyButton }
procedure TmyButton.cmMouseEnter(var msg: TMessage);
begin
if Assigned(fMouseEnter) then
fMouseEnter(self);
end;
procedure TmyButton.cmMouseLeave(var msg: TMessage);
begin
if Assigned(fMouseLeave) then
fMouseLeave(self);
end;
end.