本例子为在Form1的Panel中显示Form2窗体,请注意例子中的reintroduce关键字
//Form1 父窗体
view plaincopy to clipboardprint? 1. uses unit2;
2. procedure TForm1.FormCreate(Sender: TObject); 3. begin
4. form2 := TForm2.Create(Panel,self); 5. form2.BorderStyle := bsNone; 6. form2.WindowState := wsMaximized; 7. form2.Parent := Panel; 8. form2.Show; 9. end;
//Form2 子窗体
view plaincopy to clipboardprint? 1. uses Unit1; 2. private
3. FOwnerForm : TForm; 4. end; 5.
6. constructor Create(AOwner: TComponent; OwnerForm: TForm ); reintroduce;//响应父窗体事件的关键
7.
8. constructor TForm2.Create(AOwner: TComponent; OwnerForm: TForm);
9. begin
10. inherited Create(Aowner);
11. FOwnerForm := OwnerForm; 12. end; 13.
14. //事件触发(在FORM2中来响应FORM1的事件) 15. procedure TForm2.Button1Click(Sender: TObject); 16. begin
17. if Self.FOwnerForm.ClassType = TForm1 then 18. begin
19. ShowMessage('按下我了!'); 20. end; 21. end;
因篇幅问题不能全部显示,请点此查看更多更全内容