Sign in Join
Wiki copytemporary

Revision 1 of 1, by Paskal on 1-21-2022. The page as it is now.

TToolBar

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.

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;

See also


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.