Form1
uses unit2;
procedure TForm1.FormCreate(Sender: TObject);
begin
form2 := TForm2.Create(Panel,self);
form2.BorderStyle := bsNone;
form2.WindowState := wsMaximized;
form2.Parent := Panel;
form2.Show;
end;
Form2
uses Unit1;
private
FOwnerForm : TForm;
end;
constructor Create(AOwner: TComponent; OwnerForm: TForm ); reintroduce;//响应父窗体事件的关键
constructor TForm2.Create(AOwner: TComponent; OwnerForm: TForm);
begin
inherited Create(Aowner);
FOwnerForm := OwnerForm;
end;
事件触发(在FORM2中来响应FORM1的事件)
procedure TForm2.Button1Click(Sender: TObject);
begin
if Self.FOwnerForm.ClassType = TForm1 then
begin
ShowMessage('按下我了!');
end;
end;
时间: 2024-11-01 17:18:59