TPanel/de: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: TPanel/de
| Old | New | Line | |
|---|---|---|---|
| 1 | + | Ein **TPanel**  ist eine Komponente, die ein Panel auf einem Formular erstellt. Das TPanel ist in der Registerkarte [[Standard tab|Standard]] der [[Component Palette|Komponentenpalette]] eingeordnet. Ein TPanel kann als sichtbarer Container für andere Komponenten fungieren. | |
| 2 | + | ||
| 3 | + | ## Beispiel | |
| 4 | + | ||
| 5 | + | Eine Möglichkeit zur Verwendung von Panels besteht im Ein- und Ausblenden mehrerer Komponenten. Anstatt einzelne Komponenten ein- und auszublenden, können Sie mit nur einem Befehl das Panel und alle untergeordneten Komponenten ein- und ausblenden. In diesem Beispiel werden die folgenden Komponenten genutzt: [[TButton]] und [[TShape]] | |
| 6 | + | ||
| 7 | + | ### Erstellen des Codes | |
| 8 | + | ||
| 9 | + | - Erstellen Sie eine neue leere [[Graphical User Interface|Graphische Benutzeroberfläche]] mit dem [[TForm|Formular]] Form1 | |
| 10 | + | - Erstellen Sie ein OnCreate-Ereignis für das Formular, indem Sie darauf klicken, in den Objektinspektor und dort in die Registerkarte "Ereignisse" wechseln und anschließend das OnCreate-Ereignis auswählen. Klicken Sie den Button \[...\] oder klicken Sie doppelt auf das eben erstellte Formular. | |
| 11 | + | - Fügen Sie den folgenden Code hinzu (vervollständigen Sie die fehlenden Teile): | |
| 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 | + | ## Siehe auch | |
| 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/de", as it stood on 2020-03-08 after a change by Techno, 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).* |
