求示範 請寫出一個可偵測 Mouse Enter & Leave 的事件(event),傾其所有 60 分,不夠可再加,需有 OnMouseEnter

  • 主题发起人 主题发起人 jiichen
  • 开始时间 开始时间
J

jiichen

Unregistered / Unconfirmed
GUEST, unregistred user!
求示範 請寫出一個可偵測 Mouse Enter &amp; Leave 的事件(event),傾其所有 60 分,不夠可再加,需有 OnMouseEnter &amp; OnMouseLeave 的事件!(60分)<br />
 
我只會這樣使用,但我想讓此控件在 Object Inspector 中出現
OnMouseEnter &amp; OnMouseLeave

TPanelJC = class(TPanel)
private
{ Private declarations }
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(Owner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }

end;
 
给你贴一段,见议你多多研究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.
 
謝謝 balaschen 詳細的解說,VCL 有看過了,但是
太複雜了,我的層次太低,實在看不懂!
分先為你加上,可不可以請教最後
那邊為何要使用
inherited Create(AOwner);
inherited Destroy;

試過只用 inherited; 也行,兩者有何差異嗎?

 
接受答案了.
 
后退
顶部