TPageControl
│
English (en) │
suomi (fi) │
français (fr) │
русский (ru) │
中文(中国大陆) (zh_CN) │
TPageControl is a multi-page component that provides a container to hold a variety of controls per page. Much like a real-world notebook, it displays a "tab" per page so that the user can quickly switch between pages. Each page can contain its own selection of controls.
TPageControl is a descendant of TWinControl and can be found on the Common Controls tab of the Component Palette.
Unlike a TTabControl, each tab is connected to its own page. TPageControl's pages are accessible through its (non published) array-like Pages property.
The currently active page is accessible through the ActivePage or ActivePageIndex properties.
The event OnChange is fired when the user selects another page. The event OnChanging occurs before the active page is changed; it has a parameter AllowChange which can be set to false to prevent the change to the new page, for example because data input in the old page is incorrect.
Adding a page
In order to add a page to a TPageControl right-click on it in design mode to show its context menu, then select Add Page.
At runtime you first create a TabSheet as usual, then assign the PageControl to its Parent.
procedure TForm1.Button4Click(Sender: TObject);
var
tab: TTabsheet;
begin
tab := TTabsheet.Create(Self);
tab.Caption := 'New page';
tab.Parent := PageControl1;
end;
Deleting a Page
There are different ways of "deleting" a page from a tabsheet. All the approaches listed below would cause the target page tab to disappear from the control. Giving the end-user an effect of deleting a page. Though the page might remain available in the code.
Hide the tab
The following code simply hides the tab from the pagecontrol, meaning that the user will not longer be able to select it manually. However, the page will still be accessible by code at runtime.
Tabsheet2.TabVisible := false;
Changing the Parent
You can change Tab's parent to a different control or even to nil The method is useful when you need to move the sheet from one TabControl to another OR you want to show the page again later OR you just need to keep controls intact.
Tabsheet2.Parent := nil;
Freeing the page
The method can be used when you don't need the control itself anymore (as well as it's children)
TabSheet2.Free;
TabSheet2:=nil; // this is optional
Similar controls
- TTabControl: looks similar to TPageControl, however, possesses only a single page.
- TNotebook: contains multiple tabs like the TPageControl, but there are no tabs. The user must write code to switch between tabs.
See also