C
chenyushanshan0
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure LabelClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
mylabel:array of tlabel;
i:integer;
begin
setlength(mylabel,4);
for i:=1 to 3 do
begin
myLabel:=tLabel.Create(self);
mylabel.Parent:=form1;
mylabel.top:=i*60;
mylabel.left:=i*30;
mylabel.caption:='sdfasdeqwrfrtrt'+inttostr(i);
mylabel.OnClick := LabelClick;
end;
end;
procedure TForm1.LabelClick(Sender: TObject);
begin
//如何才能在程序运行时得知我点击的控件名称
{不能采用label的位置来判断}
end;
end.
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure LabelClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
mylabel:array of tlabel;
i:integer;
begin
setlength(mylabel,4);
for i:=1 to 3 do
begin
myLabel:=tLabel.Create(self);
mylabel.Parent:=form1;
mylabel.top:=i*60;
mylabel.left:=i*30;
mylabel.caption:='sdfasdeqwrfrtrt'+inttostr(i);
mylabel.OnClick := LabelClick;
end;
end;
procedure TForm1.LabelClick(Sender: TObject);
begin
//如何才能在程序运行时得知我点击的控件名称
{不能采用label的位置来判断}
end;
end.