delphi动态生成多个label控件
触发button1的click事件,一次动态生成6(如果是n个呢?)个label控件,包括每个label自身的onclick....
触发button1的click事件,一次动态生成6(如果是n个呢?)个label控件,包括每个label自身的onclick.
展开
1个回答
展开全部
procedure TForm1.MyOnClick(Sender: Tobject);
begin
ShowMessage((Sender as TLabel).Caption+' is clicked');
end;
procedure TForm1.btn1Click(Sender: TObject);
var
i,n:Integer;
lbl: TLabel;
begin
n:=6;
for i:=1 to n do
begin
lbl:= TLabel.Create(Application);
lbl.Parent := Self;
lbl.Caption := 'lbl'+IntToStr(i);
lbl.Top := 175;
lbl.Height := 75;
lbl.Width :=75 ;
lbl.Left := i* lbl.Width + 10;
lbl.OnClick := MyOnClick;
end;
end;
begin
ShowMessage((Sender as TLabel).Caption+' is clicked');
end;
procedure TForm1.btn1Click(Sender: TObject);
var
i,n:Integer;
lbl: TLabel;
begin
n:=6;
for i:=1 to n do
begin
lbl:= TLabel.Create(Application);
lbl.Parent := Self;
lbl.Caption := 'lbl'+IntToStr(i);
lbl.Top := 175;
lbl.Height := 75;
lbl.Width :=75 ;
lbl.Left := i* lbl.Width + 10;
lbl.OnClick := MyOnClick;
end;
end;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询