procedure TForm1.FormCreate(Sender: TObject); var i:integer; bttn:array[1..8] of TLabel ; begin for i:=1 to 8 do begin Bttn[i]:=TLabel.Create(Self); bttn[i].Parent:=self; bttn[i].AutoSize:=false; Bttn[i].Tag:=i; Bttn[i].Left:=100; bttn[i].Top:=30*i; bttn[i].Caption:='标签'+inttostr(i); Bttn[i].OnClick:=btnClick; //定义单击事件。 Bttn[i].OnMouseMove:=FrmMouseMove;//定义移动事件。 end; end;
如果你的位置是开始就知道的那好做呀,上面的方法就可以了如果你的位置不是确定的那么可以这样marayLabel:array[0..7] of TLable;procedure CreateLabel; var intI:integer; begin for intI:=Low(marayLabel) to High(marayLabel) do begin marayLabel[intI]:=TLabel.create(application); marayLabel[intI].Visible:=false; marayLabel[intI].parent:=from; end; end;procedure ShowLabel(intLeft:integer; intTop:integer; strCaption:string; intIndex:integer); begin marayLabel[intIndex].caption:=strCaption; marayLabel[intIndex].Left:=intLeft; marayLabel[intIndex].Top:=intTop; marayLabel[intIndex].visible:=true; end;//这样应该可以了,呵呵
如果你的位置是开始就知道的那好做呀,上面的方法就可以了如果你的位置不是确定的那么可以这样marayLabel:array[0..7] of TLable;procedure CreateLabel; var intI:integer; begin for intI:=Low(marayLabel) to High(marayLabel) do begin marayLabel[intI]:=TLabel.create(application); marayLabel[intI].Visible:=false; marayLabel[intI].parent:=from; end; end;procedure ShowLabel(intLeft:integer; intTop:integer; strCaption:string; intIndex:integer); begin marayLabel[intIndex].caption:=strCaption; marayLabel[intIndex].Left:=intLeft; marayLabel[intIndex].Top:=intTop; marayLabel[intIndex].visible:=true; end;//这样应该可以了,呵呵
Label1.Parent := Panel1;
Label1.Name := 'Label1';
Label1.Left := 100; //就这两句
Label1.Top := 100; //就这两句
Label1:TLabel;
begin
Label1 := TLabel.Create(nil);
Label1.Parent := Panel1;
Label1.Name := 'Label1';
Label1.Left := 100; //就这两句
Label1.Top := 100; //就这两句
end;可以吧??
var
i:integer;
bttn:array[1..8] of TLabel ;
begin
for i:=1 to 8 do
begin
Bttn[i]:=TLabel.Create(Self);
bttn[i].Parent:=self;
bttn[i].AutoSize:=false;
Bttn[i].Tag:=i;
Bttn[i].Left:=100;
bttn[i].Top:=30*i;
bttn[i].Caption:='标签'+inttostr(i);
Bttn[i].OnClick:=btnClick; //定义单击事件。
Bttn[i].OnMouseMove:=FrmMouseMove;//定义移动事件。
end;
end;
Bttn[i].OnMouseMove:=FrmMouseMove;//定义移动事件。去掉上面这两句。
var
intI:integer;
begin
for intI:=Low(marayLabel) to High(marayLabel) do
begin
marayLabel[intI]:=TLabel.create(application);
marayLabel[intI].Visible:=false;
marayLabel[intI].parent:=from;
end;
end;procedure ShowLabel(intLeft:integer; intTop:integer; strCaption:string; intIndex:integer);
begin
marayLabel[intIndex].caption:=strCaption;
marayLabel[intIndex].Left:=intLeft;
marayLabel[intIndex].Top:=intTop;
marayLabel[intIndex].visible:=true;
end;//这样应该可以了,呵呵
var
intI:integer;
begin
for intI:=Low(marayLabel) to High(marayLabel) do
begin
marayLabel[intI]:=TLabel.create(application);
marayLabel[intI].Visible:=false;
marayLabel[intI].parent:=from;
end;
end;procedure ShowLabel(intLeft:integer; intTop:integer; strCaption:string; intIndex:integer);
begin
marayLabel[intIndex].caption:=strCaption;
marayLabel[intIndex].Left:=intLeft;
marayLabel[intIndex].Top:=intTop;
marayLabel[intIndex].visible:=true;
end;//这样应该可以了,呵呵
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure btnClick(Sender:TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btnClick(Sender:TObject);
begin
ShowMessage(Format('No.%d 被单击啦!',[(Sender as TLabel).Tag]));
end;procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
bttn:array[1..8] of TLabel ;
begin
for i:=1 to 8 do
begin
Bttn[i]:=TLabel.Create(Self);
bttn[i].Parent:=self;
bttn[i].AutoSize:=false;
Bttn[i].Tag:=i;
Bttn[i].Left:=100;
bttn[i].Top:=30*i;
bttn[i].Caption:='标签'+inttostr(i);
Bttn[i].OnClick:=btnClick; //定义单击事件。
end;
end;end.