Sign in Join
Wiki copytemporary

TPanel: what changed

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

Title: TPanel

OldNewLine
1+**TPanel** ![](/wiki-images/5/57/Tpanel.png) is a component that creates a panel on a form. A TPanel is a descendant of [[TWinControl]] and is available under the [[Standard tab]] of the [[Component Palette]]. A TPanel can act as a visible container for other components.
2+
3+## Example
4+
5+One way to use panels is when the control group is displayed and hidden. Instead of showing or hiding individual controls, you can hide and show the panel and all of its child controls with a single command. In this example, the following components are used: [[TButton]], [[TShape]]
6+
7+### Create code
8+
9+- Create a new blank [[Graphical User Interface|GUI]] application with the [[TForm|form]] Form1
10+- Create the OnCreate event handler for the form, by clicking on your form, use the Object Inspector, the tab events, select the OnCreate event and click the button \[...\] or double click the button in the form.
11+- Add following code (Complete the missing parts):
12+
13+``` pascal
14+
15+unit Unit1;
16+
17+{$mode objfpc}{$H+}
18+
19+interface
20+
21+uses
22+ Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
23+
24+type
25+
26+ { TForm1 }
27+
28+ TForm1 = class(TForm)
29+ procedure FormCreate(Sender: TObject);
30+ private
31+ aPanel:TPanel;
32+ procedure aButtonClick(Sender: TObject);
33+ public
34+
35+ end;
36+
37+var
38+ Form1: TForm1;
39+
40+implementation
41+
42+{$R *.lfm}
43+
44+{ TForm1 }
45+
46+procedure TForm1.FormCreate(Sender: TObject);
47+var
48+ aButton:TButton;
49+
50+ aShape1,aShape2:TShape;
51+begin
52+ Caption :='Panel demo';
53+ aButton:=TButton.Create(Self);
54+ aButton.Parent:=Self;
55+ aButton.Caption:= 'Show/Hide';
56+ aPanel:=TPanel.Create(Self);
57+ aPanel.Parent:=Self;
58+ aPanel.Caption:='';
59+ aShape1:=TShape.Create(aPanel);
60+ aShape1.Parent:=aPanel;
61+ aShape1.Shape:=stStar;
62+ aShape1.Top := 5;
63+ aShape2:=TShape.Create(aPanel);
64+ aShape2.Parent:=aPanel;
65+ aShape2.Shape:=stStar;
66+ aShape2.Top := 5;
67+ aShape2.Left:=aShape1.Width+10;
68+ aPanel.Height:=aShape1.Height+10;
69+ aButton.Top:=aPanel.Height+10;
70+ aButton.OnClick:=@aButtonClick;
71+ Height := aButton.Top+aButton.Height+10;
72+end;
73+
74+procedure TForm1.aButtonClick(Sender: TObject); //the event handler for the button
75+begin
76+ if (Sender is TButton)
77+ then begin
78+ if aPanel.Visible then aPanel.Visible := false else aPanel.Visible := true;
79+ end;
80+end;
81+end.
82+```
83+
84+## See also
85+
86+- [[doc:lcl/extctrls/tpanel.html|TPanel doc]]
87+- [[TBevel]]
88+- [[TFrame]]
89+- [[TFlowPanel]]
90+
91+---
92+*From the Free Pascal wiki, page "TPanel", as it stood on 2019-10-04 after a change by Djzepi, 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