Sign in Join
Wiki copytemporary

TPageControl: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11![](/wiki-images/4/44/Tpagecontrol.png) **`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.
22
33`TPageControl` is a descendant of [[TWinControl]] and can be found on the [[Common Controls tab]] of the [[Component Palette]].
44
55Unlike a [[TTabControl]], each tab is connected to its own page. `TPageControl`'s pages are accessible through its (non published) array-like `Pages` property.
66
77The currently active page is accessible through the `ActivePage` or `ActivePageIndex` properties.
88
99The 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.
1010
1111## Adding a page
1212
1313In order to add a page to a `TPageControl` right-click on it in design mode to show its context menu, then select *Add Page*.
1414
1515At runtime you first create a `TabSheet` as usual, then assign the `PageControl` to its `Parent`.
1616
1717``` Pascal
1818procedure TForm1.Button4Click(Sender: TObject);
1919var
2020 tab: TTabsheet;
2121begin
2222 tab := TTabsheet.Create(Self);
2323 tab.Caption := 'New page';
2424 tab.Parent := PageControl1;
2525end;
2626```
2727
28-<figure>
29-<img src="component-TPageControl.png" title="component-TPageControl.png" />
30-<figcaption>component-TPageControl.png</figcaption>
31-</figure>
28+![](/wiki-images/c/c2/Component-TPageControl.png)
3229
3330## Deleting a Page
3431
3532There 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.
3633
3734### Hide the tab
3835
3936The 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.
4037
4138``` pascal
4239Tabsheet2.TabVisible := false;
4340```
4441
4542### Changing the Parent
4643
4744You can change Tab's parent to a different control or even to **[[Nil|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.
4845
4946``` pascal
5047Tabsheet2.Parent := nil;
5148```
5249
5350### Freeing the page
5451
5552The method can be used when you don't need the control itself anymore (as well as it's children)
5653
5754``` pascal
5855TabSheet2.Free;
5956TabSheet2:=nil; // this is optional
6057```
6158
6259## Similar controls
6360
6461- [[TTabControl]]: looks similar to `TPageControl`, however, possesses only a single page.
6562- [[TNotebook]]: contains multiple tabs like the `TPageControl`, but there are no tabs. The user must write code to switch between tabs.
6663
6764## See also
6865
6966- [[doc:lcl/comctrls/tpagecontrol.html|TPageControl doc]]
7067- [[doc:lcl/extctrls/multi-pagecontrols.html|Multi-page controls doc]]
7168
7269---
7370*From the Free Pascal wiki, page "TPageControl", as it stood on 2021-09-07 after a change by Skalogryz, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history