Difference between revisions of "TToolBar"
From Lazarus wiki
Jump to navigationJump to searchm |
|||
(One intermediate revision by the same user not shown) | |||
Line 4: | Line 4: | ||
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. | 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. | ||
+ | |||
+ | == Example == | ||
+ | This example adds buttons in a toolbar during runtime. | ||
+ | |||
+ | 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. | ||
+ | |||
+ | <syntaxhighlight lang="Pascal">procedure AddButtons(ToolBar: TToolBar; const ButtonCaptions: array of String); | ||
+ | var | ||
+ | i: integer; | ||
+ | begin | ||
+ | for i := 0 to High(ButtonCaptions) do | ||
+ | begin | ||
+ | with TToolButton.Create(ToolBar) do | ||
+ | begin | ||
+ | Parent := ToolBar; | ||
+ | Caption := ButtonCaptions[i]; | ||
+ | if (ButtonCaptions[i] = '|') then | ||
+ | Style := tbsSeparator | ||
+ | else | ||
+ | Style := tbsButton; | ||
+ | AutoSize := True; | ||
+ | Left := Parent.Width; //Buttons are added from left to right, otherwise the direction might be random, usually from right to left | ||
+ | end; | ||
+ | end; | ||
+ | end; | ||
+ | |||
+ | procedure TForm1.FormCreate(Sender: TObject); | ||
+ | var | ||
+ | ToolBar: TToolBar; | ||
+ | begin | ||
+ | ToolBar := TToolBar.Create(Self); | ||
+ | ToolBar.Parent := Self; | ||
+ | ShowMessage(IntToStr(ToolBar.ButtonCount)); | ||
+ | AddButtons(ToolBar, ['New', 'Save', '|', 'Cut', 'Copy', 'Paste']); | ||
+ | ToolBar.ShowCaptions := True; | ||
+ | ToolBar.Height := 40; | ||
+ | ToolBar.ButtonWidth := 75; | ||
+ | ShowMessage(IntToStr(ToolBar.ButtonCount)); | ||
+ | end; | ||
+ | </syntaxhighlight> | ||
== See also== | == See also== |
Latest revision as of 14:38, 21 January 2022
│
English (en) │
français (fr) │
русский (ru) │
TToolBar is a visible component on the Common Controls tab of the Component Palette that provides a tool bar with TToolButtons.
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.
Example
This example adds buttons in a toolbar during runtime.
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.
procedure AddButtons(ToolBar: TToolBar; const ButtonCaptions: array of String);
var
i: integer;
begin
for i := 0 to High(ButtonCaptions) do
begin
with TToolButton.Create(ToolBar) do
begin
Parent := ToolBar;
Caption := ButtonCaptions[i];
if (ButtonCaptions[i] = '|') then
Style := tbsSeparator
else
Style := tbsButton;
AutoSize := True;
Left := Parent.Width; //Buttons are added from left to right, otherwise the direction might be random, usually from right to left
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
ToolBar: TToolBar;
begin
ToolBar := TToolBar.Create(Self);
ToolBar.Parent := Self;
ShowMessage(IntToStr(ToolBar.ButtonCount));
AddButtons(ToolBar, ['New', 'Save', '|', 'Cut', 'Copy', 'Paste']);
ToolBar.ShowCaptions := True;
ToolBar.Height := 40;
ToolBar.ButtonWidth := 75;
ShowMessage(IntToStr(ToolBar.ButtonCount));
end;
See also