动态添加页面控件并嵌入表单? [英] Dynamically add tab sheets to page control and embed a form?

查看:160
本文介绍了动态添加页面控件并嵌入表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个由页面控件组成的模块。默认情况下,此页面控件( TPageControl )不应该有任何选项卡( TTabSheet ),但是在初始化时,它应该动态地插入这些页面并在其中嵌入一个表单。



问题在于知道如何将页签插入到页面控件中。如何创建这个?一旦它被创建,以及每个表单中的表单,我如何迭代它们来销毁表单?

解决方案

1。如何动态创建选项卡?

  procedure TForm1.Button1Click(Sender:TObject); 
var
TabSheet:TTabSheet;
begin
TabSheet:= TTabSheet.Create(PageControl1);
TabSheet.Caption:='New Tab Sheet';
TabSheet.PageControl:= PageControl1;
结束

2。如何在表单中嵌入表单?



要在表单中插入表单,只需使用父变更: / p>

  Form2.Parent:= TabSheet; 
Form2.Show;

3。摧毁它时,我需要手动释放嵌入到标签页中的表单吗?



不,释放选项卡。如果表单具有标签页,或者更准确地说, TWinControl 作为其 ,父母在释放自己时会照顾他们的释放。


I'm working on a module which consists of a page control. By default, this page control (TPageControl) shouldn't have any tab sheets (TTabSheet), but upon initialization, it should dynamically insert these pages and embed a form inside of it.

The issue comes with knowing how to insert a tab sheet into the page control. How do I create this? And once it's created, along with the forms inside each one, how do I iterate through them to destroy the forms?

解决方案

1. How to dynamically create a tab sheet ?

procedure TForm1.Button1Click(Sender: TObject);
var
  TabSheet: TTabSheet;
begin
  TabSheet := TTabSheet.Create(PageControl1);
  TabSheet.Caption := 'New Tab Sheet';
  TabSheet.PageControl := PageControl1;
end;

2. How to embed a form inside of a tab sheet ?

To insert a form inside of a tab sheet use simply a parent change:

Form2.Parent := TabSheet;
Form2.Show;

3. Will I need to manually free the forms embedded into a tab sheet when destroying it ?

No, it is enough to free a tab sheet. In case when the forms will have a tab sheet, or to be more precise, the TWinControl as their Parent, that parent will take care of their release when freeing itself.

这篇关于动态添加页面控件并嵌入表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆