我想在TTimage加一个onmouseleave事件,应如何实现?(100分)

  • 主题发起人 主题发起人 flysand
  • 开始时间 开始时间
F

flysand

Unregistered / Unconfirmed
GUEST, unregistred user!
从TTimage继承,加一个onmouseleave事件,应如何实现?
 
很多了,这里 :

http://www.delphibbs.com/delphibbs/dispq.asp?lid=393541
 
onMouseMove事件是经常发生的。应该编写一个新Timage构件。
如下:
unit image1;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls;

type
TNewimage = class(TImage)
private
FOnMouseLeave: TNotifyEvent;
FOnMouseEnter: TNotifyEvent;
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
//请自己修改
RegisterComponents('Samples', [TNewimage]);
end;

{ timage1 }

procedure TNewimage.CMMouseEnter(var Message: TMessage);
begin
inherited;
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;

procedure TNewimage.CMMouseLeave(var Message: TMessage);
begin
inherited;
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;

end.

//就行了.
 
type
TLImage = Class(TImage)
private
FOnMouseLeave : TNotifyEvent;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
protected

public

published
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TLImage]);
end;

procedure TLImage.CMMouseLeave(var Message: TMessage);
begin
inherited;
if assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;
 
unit mycoolimage;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls;

type
Tmycoolimage = class(TImage)
private
{ Private declarations }
FOnMouseEnter:TNotifyEvent;
FOnMouseLeave:TNotifyEvent;
protected
{ Protected declarations }
Procedure DoMouseEnter(Var Message:TMessage);message CM_MOUSEENTER;
Procedure DoMouseLeave(Var Message:TMessage);message CM_MOUSELEAVE;
public
{ Public declarations }
published
{ Published declarations }
Property OnMouseEnter:TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
Property OnMouseLeave:TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;

procedure Register;

implementation
procedure TmycoolImage.DoMouseEnter(var Message:TMessage);
begin
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;
procedure TmycoolImage.DoMouseLeave(var Message:TMessage);
begin
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;
procedure Register;
begin
RegisterComponents('Samples', [Tmycoolimage]);
end;

end.

我用的就是这个,改都不用改,直接就可以用。:)
 
多人接受答案了。
 
后退
顶部