[Overview][Constants][Types][Classes][Procedures and functions][Index] | Reference for unit 'ComCtrls' (#lcl)

# TToolBar

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

TToolbar manages tool buttons and other controls, arranging them in rows and automatically adjusting their sizes and positions.

## Declaration

Source position: comctrls.pp line 1521

`type TToolBar = class(TToolWindow)`
`protected`
`procedure WSRegisterClass; override;` |  | WSRegisterClass - Register this Class for the current Widget Set
`procedure AdjustClientRect(); override;` |  | AdjustClientRect - method for adjusting the size and position of the client control
`function GetControlClassDefaultSize; override;` |  | GetControlClassDefaultSize - returns its own defaults, overriding the inherited values
`procedure DoAutoSize; override;`
`procedure CalculatePreferredSize(); override;` |  | CalculatePreferredSize - find default/preferred height and width
`function CheckMenuDropdown(); virtual;` |  | CheckMenuDropdown - returns True if there is a checked dropdown menu
`procedure ClickButton(); virtual;` |  | ClickButton - software emulation of the OnClick event
`procedure CreateParams(); override;` |  | CreateParams - create parameters for this windowed class
`procedure CreateWnd; override;` |  | CreateWnd - Creates the Window
`procedure ControlsAligned; override;` |  | ControlsAligned - called by AlignControls after aligning controls
`function FindButtonFromAccel();` |  | FindButtonFromAccel - returns the Button corresponding to the specified accelerator key
`procedure FontChanged(); override;` |  | FontChanged - method to cope with change in font
`procedure ParentFontChanged; override;` |  | ParentFontChanged - method for coping with change in parent font
`procedure Loaded; override;` |  | Loaded makes a number of checks, using client size if specified, and copying appropriate flags, fonts, text etc, makes list of child controls to notify them of any changes, then calls inherited Loaded
`procedure Notification(); override;` |  | Notification - calls inherited Notification, then takes action depending on Operation
`procedure RepositionButton();` |  | RepositionButton - method for re-positioning a button
`procedure RepositionButtons();` |  | RepositionButtons - method for re-positioning several buttons
`function WrapButtons();` |  | WrapButtons - returns True if changing to NewHeight and NewWidth causes wrapping of buttons
`public`
`constructor Create(); override;` |  | Create - constructor for TToolBar: calls inherited Create and sets many formatting and size defaults
`destructor Destroy; override;` |  | Destroy - destructor for TToolBar: frees buttons and links then calls inherited Destroy
`procedure FlipChildren(); override;` |  | FlipChildren - reverse the order of the child components
`procedure BeginUpdate; virtual;` |  | BeginUpdate - starts the update process
`procedure EndUpdate; virtual;` |  | EndUpdate - finishes the update process
`procedure Paint; override;` |  | The default paint handler for the class
`procedure SetButtonSize();` |  | SetButtonSize - stores new values for height and width
`function CanFocus; override;` |  | CanFocus - is the current window allowed to receive focus?
`property ButtonCount: Integer; [r]` |  | ButtonCount - the number of buttons on the ToolBar
`property Buttons: TToolButton; [r]` |  | Lists the tool buttons (TToolButton) in the toolbar.
`property ButtonList: TList; [r]` |  | ButtonList - the list of Buttons (as a TList)
`property RowCount: Integer; [r]` |  | RowCount - the number of Rows of Buttons
`published`
`property Align;` |  | Used to align the control to the top, bottom, left or right of its client.
`property Anchors;`
`property AutoSize;` |  | Whether auto-size is to be used
`property BorderSpacing;` |  | Determines the border spacing for this control
`property BorderWidth;` |  | Property to determine width of the window's border
`property ButtonHeight: Integer; [rw]` |  | ButtonHeight - the height of the buttons
`property ButtonWidth: Integer; [rw]` |  | ButtonWidth - the width of the buttons
`property Caption;` |  | Caption - the text-string appearing on the Control, usually used to identify its function
`property ChildSizing;` |  | Definitions of how any child control is to be sized
`property Constraints;` |  | Determine Constraints (max and min height and width) for this control
`property Color;` |  | Determine the colour for the current control
`property DisabledImages: TCustomImageList; [rw]` |  | The Images on the Image List that are NOT selected for display
`property DragCursor;` |  | DragCursor - the style of cursor to be used during the Drag process
`property DragKind;` |  | DragKind - what sort of dragging? Drag or Dock
`property DragMode;` |  | DragMode - whether manual or automatic
`property EdgeBorders;` |  | EdgeBorders - which borders form th eedge
`property EdgeInner;` |  | EdgeInner - this toolbar has an inner edge
`property EdgeOuter;` |  | EdgeOuter - this toolbar has an outer edge
`property Enabled;` |  | Whether the control is Enabled. If not, it usually appears 'greyed-out'
`property Flat: Boolean; [rw]` |  | Should the toolbuttons be displayed Flat (rather than in relief)? Default false
`property Font;` |  | The Font to be used for text in this control
`property Height;` |  | Height - the vertical dimension of the control
`property HotImages: TCustomImageList; [rw]` |  | The Images on the Image list that are selected for display
`property Images: TCustomImageList; [rw]` |  | The Images to be displayed on the buttons
`property Indent: Integer; [rw]` |  | Indent - the amount by which the buttons should be indented Default is 1
`property List: Boolean; [rw]` |  | Should the contents of the toolbar be displayed as a List? Default false
`property ParentColor;` |  | ParentColor - should the control have the same colour as the parent? Default is true
`property ParentFont;` |  | ParentFont - should the control use the same font as the parent? Default is true
`property ParentShowHint;` |  | ParentShowHint - does the control adopt the same hinting behaviour as its parent? Default is true
`property PopupMenu;` |  | PopupMenu - a context-sensitive menu that pops up when the right mouse button is clicked over this control
`property ShowCaptions: Boolean; [rw]` |  | ShowCaptions - should the captions be shown for the buttons? (Default False)
`property ShowHint;` |  | Flag to determine: Is hint to be displayed for this control?
`property TabOrder;` |  | The place this control occupies in the list of tabs
`property TabStop;` |  | Is the control in the sequence of controls accessed by successive presses of the Tab key?
`property Transparent: Boolean; [rw]` |  | Is the ToolBar to be Transparent? Default False
`property Visible;` |  | Visible - can the control be seen?
`property Wrapable: Boolean; [rw]` |  | Wrapable - enables wrapping buttons to the next row if there are too many for the current row
`property OnClick;` |  | Event Handler for mouse click
`property OnContextPopup;` |  | Event handler to supply information when a context-sensitive pop-up menu is required
`property OnDblClick;` |  | Event Handle for mouse double-click
`property OnDragDrop;` |  | Event handler for the Drag-Drop manoeuvre
`property OnDragOver;` |  | Event handler for the case when a control is dragged over another control
`property OnEndDrag;` |  | Event handler for the end of a dragging process
`property OnEnter;` |  | OnEnter - event handler for when the mouse enters the control, and the control receives focus
`property OnExit;` |  | OnExit - event handler for when the mouse leaves the control and it loses focus
`property OnMouseDown;` |  | Event handler for when a mouse button is pressed down
`property OnMouseMove;` |  | Event handler for mouse movement within the current control
`property OnMouseUp;` |  | Event handler for when the mouse button is released, ie "up"
`property OnMouseEnter;` |  | Event handler for when the mouse enters the area of the current control
`property OnMouseLeave;` |  | Event handler for when the mouse leaves the area of the current control
`property OnResize;` |  | Event Handler for resize of control
`property OnChangeBounds;` |  | Event handler for a change in bounds of the control
`property OnStartDrag;` |  | Event handler for start of dragging process
`end;`

## Inheritance

`TToolBar` |  | TToolbar manages tool buttons and other controls, arranging them in rows and automatically adjusting their sizes and positions.
`TToolWindow`
?
`TObject`

## Description

TToolbar is a container for tool buttons (TToolButton). it provides an easy way to arrange and manage visual controls.

- All tool buttons on a toolbar maintain a uniform width and height.
- Other controls can sit on a toolbar. These controls (which are held in place by invisible tool buttons) maintain a uniform height.
- Controls can automatically wrap around and start a new row when they do not fit horizontally on the toolbar.
- The Flat property allows the background to show through the toolbar and gives pop-up borders to the tool buttons.
- Spaces and dividers (which are in fact specially configured tool buttons) can group controls on the toolbar both visually and functionally.

Typically, the tool buttons correspond to items in an application's menu and gives the user more direct access to the application's commands.

## See also

#LCL.ComCtrls.TToolButton |  | TToolButton is a button control in a TToolBar object.
HowToUseStdCtrls |  | How to use StdCtrls, ComCtrls or ExtCtrls

## Example

    { 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;
        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;

The latest version of this document can be found at lazarus-ccr.sourceforge.net.