//革命尚未成功,同志仍须努力
//注意uses中必须加入extctrls
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TmyImage=class( tImage)
private
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
img:tmyimage;
procedure TmyImage.CMMouseEnter(var Message: TMessage);
begin
//进入事件
self.Canvas.TextOut(1,1,'enter');
end;
procedure TmyImage.CMMouseLeave(var Message: TMessage);
begin
//离开事件
self.Canvas.TextOut(1,1,'leave');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
img:=tmyimage.Create(self);
img.left:=10;
img.Top:=10;
img.Parent:=self;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if img<>nil then img.free;
end;
end.