请问怎么样在delphi中动态的创建一个控件啊!
比如说,
我现在窗体上只有有一个label1,在程序运行时,
我点按钮,就会生成一个label2.
他的label2.caption:='我要的';同时
label1.caption:='生成label1'
还有,我创建以后,我想点一个按钮来删除label2,
label1.caption:='删除label1'
比如说,
我现在窗体上只有有一个label1,在程序运行时,
我点按钮,就会生成一个label2.
他的label2.caption:='我要的';同时
label1.caption:='生成label1'
还有,我创建以后,我想点一个按钮来删除label2,
label1.caption:='删除label1'
lb: TLabel;
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
lb := TLabel.Create(self);
lb.Parent := Form1;
lb.Top := Label1.Top;
lb.Left := Label1.Left + Label1.Width;
lb.AutoSize := False;
lb.Width := Label1.Width;
lb.Caption := '我要的';
label1.caption:='生成label1';
end;procedure TForm1.Button2Click(Sender: TObject);
begin
lb.Free;
label1.caption:='删除label1';
end;end.
begin
with Tlabel.Create(self) do
begin
parent := self;
caption := 'mylabel';
name := 'mylabel';
left := 100;
top := 100;
end;
label1.Caption := 'createlabel';
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Tlabel(FindComponent('mylabel')).Free;
label1.Caption := 'deletelabel';
end;