1. Home
  2. Computing & Technology
  3. Delphi Programming

Placing a Form inside a TabSheet of a TPageControl

By Zarko Gajic, About.com

While TPageControl (located on the Win32 tab of the component palette) enables you to build a multiple page dialog or tabbed notebook type of interface, by adding components to each page of the control - you might sometimes want to host an entire form in a page.

Here's how to dynamically place a Delphi Form into a TabSheet of a TPageControl - while still being able to use a Form as a stand-alone window.

Note: We are placing an instance of a "TMyForm" form in a new TabSheet for an existing TPageControl component named "PageControl1".

~~~~~~~~~~~~~~~~~~~~~~~~~
var
   aForm : TMyForm;
   tabSheet : TTabSheet;
begin
   //Create a new tab sheet
   tabSheet := TTabSheet.Create(PageControl1) ;
   tabSheet.PageControl := PageControl1;

   //create a form
   aForm := TMyForm.Create(tabSheet) ;
   aForm.Parent := tabSheet;
   aForm.Align := alClient;
   aForm.BorderStyle := bsNone;
   aForm.Visible := true;
   tabSheet.Caption := aForm.Caption;

   //activate the sheet
   PageControl1.ActiveSheet := tabSheet;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to Enable the Refresh button on a DBNavigator for ReadOnly Datasets
« Logging Exceptions in Delphi Applications

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TPageControl
  6. Placing a Delphi Form inside a TabSheet of a TPageControl

©2009 About.com, a part of The New York Times Company.

All rights reserved.