Difference between revisions of "TToolBar"

From Free Pascal wiki
Jump to navigationJump to search
m
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''TToolBar''' is a container that manages tool buttons from a [[TImageList|ImageList]], arranging them in rows and automatically adjusting their sizes and positions.
+
{{TToolBar}}
  
[[File:Win7LazarusStdToolbar.png|The standard Lazarus toolbar (Windows 7)]]
+
'''TToolBar''' [[image:ttoolbar.png]] is a visible component on the [[Common Controls tab]] of the [[Component Palette]] that provides a tool bar with [[TToolButton]]s.
  
See [[doc:lcl/comctrls/ttoolbar.html|TToolBar]] in the LCL reference for details.
+
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.
  
{{LCL Components Footer|TStatusBar|TUpDown}}
+
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.
{{LCL Components}}
+
 
 +
<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==
 +
* [[doc:lcl/comctrls/ttoolbar.html|TToolBar doc]]
 +
* [[TCoolBar]]
 +
* [[TControlBar]]
  
[[Category:LCL]]
+
{{LCL Components}}
[[Category:Components]]
 

Latest revision as of 13:38, 21 January 2022

English (en) français (fr) русский (ru)

TToolBar ttoolbar.png 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


LCL Components
Component Tab Components
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn • TSpeedButton • TStaticText • TImage • TShape • TBevel • TPaintBox • TNotebook • TLabeledEdit • TSplitter • TTrayIcon • TControlBar • TFlowPanel • TMaskEdit • TCheckListBox • TScrollBox • TApplicationProperties • TStringGrid • TDrawGrid • TPairSplitter • TColorBox • TColorListBox • TValueListEditor
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TTaskDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog
Data Controls TDBNavigator • TDBText • TDBEdit • TDBMemo • TDBImage • TDBListBox • TDBLookupListBox • TDBComboBox • TDBLookupComboBox • TDBCheckBox • TDBRadioGroup • TDBCalendar • TDBGroupBox • TDBGrid • TDBDateTimePicker
Data Access TDataSource • TCSVDataSet • TSdfDataSet • TBufDataset • TFixedFormatDataSet • TDbf • TMemDataset
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TJSONPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TLvlGraphControl • TShortPathEdit • TSpinEditEx • TFloatSpinEditEx • TTreeFilterEdit • TExtendedTabControl •
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery • TSQLTransaction • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TMySQL57Connection • TSQLite3Connection • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport_Classes • TPSImport_DateUtils • TPSImport_ComObj • TPSImport_DB • TPSImport_Forms • TPSImport_Controls • TPSImport_StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHtmlDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu