急急急--- 单击Form1的Button,在Form2上生成Button? 问题是这样的:有两个Form,分别为Form1和Form2,Form1上放置了一个Button,程序运行后想实现的效果是:单击Form1上的Button,在Form2上生成一个Button,再次单击就再生成,并且生成的Button之间的Name和位置不相同(就是单击Form1的Button,在Form2上动态的生成Button并Name和位置不同)。请问这个效果如何实现?请给个Demo,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 form1 单元中添加uses Unit2 var FIndex : integer = 0;procedure TForm1.btn1Click(Sender: TObject); var sstr: string; Btn : TButton;begin sStr := 'Btn' + inttostr(Findex); Btn := TButton.Create(Form2); btn.Name := sstr; btn.Left := 100 + FIndex; Btn.Top := 100 + Findex; Inc(FIndex);end; procedure TForm1.Button1Click(Sender: TObject);var dButton:Tbutton;beginif Form2<> nil thenbegindButton:=TButton.Create(form2);dButton.Parent := Form2;dButton.Name := 'Test'+inttostr(i);dButton.Top:=i*20;dButton.Left:=0;dButton.Width:=50;dButton.Height:=20;dButton.Caption:='test'+inttostr(i);;dButton.Show;Inc(i);end;end;在D7下测试通过! 不行啊,兄弟。不能在Form2上生成,你的代码拿到Form1上可以... 1楼兄弟的代码也是正确的 不过要指定Button的Parent,2楼的兄弟提醒了我,在手动添加一个Form时,应该去掉Project中Application.Create(TForm2,Form2)(此时Options-Forms中的Form2已经加入到available中了)再在Form1的OnCreate事件中加入Form2:= TForm2.Create(Application); Form2.Visible:= True;即可。谢谢你们... Delphi2010 调试 ADOStoredProc1执行报错,一个小问题.(在线) 托盘程序弹出菜单后,不能自动关闭!!!!! 放分拉!这样的sql语句怎么解决??? 一个关于路径的问题?UP给分,不够在给! 请问让Delphi的VCL支持 UniCode 字符? (如TMemo) 怎样得到局域网中所有的计算机名或IP地址 为什么Access表老被锁定?? 急急,动态链接库问题!!! 如何在dbgrid中显示图形。 fastreport4.5:如果DetailData没有数据,如何显示其相应的header? 谢谢啦
form1 单元中添加
uses Unit2
var FIndex : integer = 0;
procedure TForm1.btn1Click(Sender: TObject);
var sstr: string;
Btn : TButton;
begin
sStr := 'Btn' + inttostr(Findex);
Btn := TButton.Create(Form2);
btn.Name := sstr;
btn.Left := 100 + FIndex;
Btn.Top := 100 + Findex;
Inc(FIndex);
end;
var
dButton:Tbutton;
beginif Form2<> nil then
begin
dButton:=TButton.Create(form2);
dButton.Parent := Form2;
dButton.Name := 'Test'+inttostr(i);
dButton.Top:=i*20;
dButton.Left:=0;
dButton.Width:=50;
dButton.Height:=20;
dButton.Caption:='test'+inttostr(i);;
dButton.Show;
Inc(i);
end;
end;
在D7下测试通过!