这分我要呀。
在form1中由Button1Click动态建立新的窗体与button2控件,
并对button2事件响应。代码如下。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
Tform2=class(Tform)
procedure Button2Click(Sender: TObject) ;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
form2:Tform2;
button2:Tbutton;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
form2:=Tform2.Create(self);//动态创建新窗体。(正式写时适当位置
//应加入form2.free以释放)
form2.Show;
button2:=Tbutton.Create(self);
button2.Parent:=form2;
//form2.Button2Click(self);
button2.onClick:=Form2.Button2Click; //将button2的响应与 //Button2Click联系起来
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
button2.Caption:='111';
form1.Caption:='111'+form1.Caption; //也可以类似写form1.button.caption
// :='hhhh'
end;
end.
最后告诉你个诀窍:输入检索关键词 动态 控件 响应
呵呵,后悔出这100分了吧。