Dynamically add tab sheets to page control and embed a form?

后端 未结 2 1574
轻奢々
轻奢々 2021-02-13 06:10

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

2条回答
  •  無奈伤痛
    2021-02-13 06:41

    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.

提交回复
热议问题