TToolBar: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: TToolBar
| Old | New | Line | |
|---|---|---|---|
| 1 | + | **TToolBar**  is a visible component on the [[Common Controls tab]] of the [[Component Palette]] that provides a tool bar with [[TToolButton|TToolButtons]]. | |
| 2 | + | ||
| 3 | + | A TToolBar act as a container that manages tool buttons with images from a [[TImageList]], arranging them in rows and automatically adjusting their sizes and positions. | |
| 4 | + | ||
| 5 | + | ## Example | |
| 6 | + | ||
| 7 | + | This example adds buttons in a toolbar during runtime. | |
| 8 | + | ||
| 9 | + | To use this example, create a new application and add the example code to the unit. Remember to add the *ComCtls* unit in the uses clause. | |
| 10 | + | ||
| 11 | + | ``` Pascal | |
| 12 | + | procedure AddButtons(ToolBar: TToolBar; const ButtonCaptions: array of String); | |
| 13 | + | var | |
| 14 | + | i: integer; | |
| 15 | + | begin | |
| 16 | + | for i := 0 to High(ButtonCaptions) do | |
| 17 | + | begin | |
| 18 | + | with TToolButton.Create(ToolBar) do | |
| 19 | + | begin | |
| 20 | + | Parent := ToolBar; | |
| 21 | + | Caption := ButtonCaptions[i]; | |
| 22 | + | if (ButtonCaptions[i] = '|') then | |
| 23 | + | Style := tbsSeparator | |
| 24 | + | else | |
| 25 | + | Style := tbsButton; | |
| 26 | + | AutoSize := True; | |
| 27 | + | Left := Parent.Width; //Buttons are added from left to right, otherwise the direction might be random, usually from right to left | |
| 28 | + | end; | |
| 29 | + | end; | |
| 30 | + | end; | |
| 31 | + | ||
| 32 | + | procedure TForm1.FormCreate(Sender: TObject); | |
| 33 | + | var | |
| 34 | + | ToolBar: TToolBar; | |
| 35 | + | begin | |
| 36 | + | ToolBar := TToolBar.Create(Self); | |
| 37 | + | ToolBar.Parent := Self; | |
| 38 | + | ShowMessage(IntToStr(ToolBar.ButtonCount)); | |
| 39 | + | AddButtons(ToolBar, ['New', 'Save', '|', 'Cut', 'Copy', 'Paste']); | |
| 40 | + | ToolBar.ShowCaptions := True; | |
| 41 | + | ToolBar.Height := 40; | |
| 42 | + | ToolBar.ButtonWidth := 75; | |
| 43 | + | ShowMessage(IntToStr(ToolBar.ButtonCount)); | |
| 44 | + | end; | |
| 45 | + | ``` | |
| 46 | + | ||
| 47 | + | ## See also | |
| 48 | + | ||
| 49 | + | - [[doc:lcl/comctrls/ttoolbar.html|TToolBar doc]] | |
| 50 | + | - [[TCoolBar]] | |
| 51 | + | - [[TControlBar]] | |
| 52 | + | ||
| 53 | + | --- | |
| 54 | + | *From the Free Pascal wiki, page "TToolBar", as it stood on 2022-01-21 after a change by Paskal, 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).* |
