怎么定义多个动态生成的相同类型控件的事件?
2个回答
展开全部
nit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure MyImageMouseDownSender( Sender:TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
aImage:TImage;
begin
aImage:=TImage.Create(Self);
aImage.Parent:=Self;
aImage.Canvas.Ellipse(1,1,100,100);
aImage.OnMouseDown:=MyImageMouseDownSender;
end;
procedure TForm1.MyImageMouseDownSender(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Sender is Timage then
ShowMessage(Timage(Sender).ClassName);
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure MyImageMouseDownSender( Sender:TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
aImage:TImage;
begin
aImage:=TImage.Create(Self);
aImage.Parent:=Self;
aImage.Canvas.Ellipse(1,1,100,100);
aImage.OnMouseDown:=MyImageMouseDownSender;
end;
procedure TForm1.MyImageMouseDownSender(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Sender is Timage then
ShowMessage(Timage(Sender).ClassName);
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询