The Delphi - Toolbars

Delphi provides several ways to produce Toolbars.

TPanel | TToolBar | TToolButton | TPageScroller | TControlBar | TCoolBar


Place a TPanel with Align=alTop and place buttons, pick lists and the like in it.

Both TBitBtn and TSpeedButton have a glyph property that is automatically set when the Action property is set (assuming that an ImageList is associated with the ActionList).

Though this is the most straight forward way to produce a toolbar, it does not perform automatic wrapping and it requires extra space because it saves each image (glyph) twice - in the ImageList and with its button.


TToolBar is a Windows component (ie, it is part of the operating system) that provides toolbar functionality. Among other things Adding buttons, separators, dividers etc. With respect to images (icons), this is more efficient than using a panel because the Actions and Toolbars can be associated with a single image list and then the ImageIndex property associates the ToolButtons with an image in that list. Thus, each image is stored only once. This association is automatic when an Action is attached to a TToolButton.

Set Flat to true to remove the "raised" borders around the buttons.

Docking with Several Toolbars

To allow the user to drag the toolbar off the form, set DragKind to dkDock. (Based on experience, DragMode can be either dmManual or dmAutomatic, the help says that it must be dmAutomatic.) You will need a TControlBar (or another component with DockSite set to true) if you want to be able to place it back in the form. (Do not set DockSite to true on the form itself. I don't like how that works)

You should also set these ToolBar properties

Problem with Wrapped Toolbars in Design Mode

You can place TEdit components on a toolbar, but its location is sort of non-controllable (unpredictable). To recreate the problem, create a toolbar with 2 lines. Then place the TEdit component on the second line. When you compile the form, the TEdit component will be placed between the buttons of the first row. I have not noticed a problem when the edit control is on the first (or only) line.


These are not on the component palette, instead, at design time, you add TToolButtons to a TToolBar by right clicking the toolbar (or a button on the TToolBar) and selecting New Button.

You will probably want to set the Style property.

You can not manually set the width of a single button (if you try, all the buttons will get the new width), but you can control the widths of separators and dividers.


TPageScroller is supposed to allow you to develop toolbars that can be scrolled sideways.

Well, it doesn't work. Some functionality is available if the toolbar's Align property is set to alNone, the Wrapable property is set to False, and the toolbar is moved to the right. But in my testcase, there were still several buttons that were never displayed.
(Tested with Delphi 5 on Windows 98)


TControlBar can be used as a docking site for a TToolBar ... IF you set the ToolBar's minimum and maximum width and set Wrapable to false. Otherwise, I suggest not using it.

I was able to break this by placing 2 toolbars on the same line (in run mode). First, resize the form so that the right-most toolbar is shortened. Then drag the right-most toolbar to the second line. Now there is no way to get it back to its original size. In addition, any buttons that are wrapped to the second line disappear (ie, they are not available). It is possible to inhibit this behaivor by making the changes suggested in the first paragraph.
(Tested with Delphi 5 on Windows 98)

You should set TControlBar.AutoSize to True so that the ControlBar will automatically resize itself to be as small as possible.

The default RowSize property is too small, increase it from 26 to 30 so that the toolbar buttons will fit.

When the user drags the toolbar off the form, it is displayed in its own window. However, if the user then clicks the x in the title bar, the toolbar window closes and there is no way for the user to get it back. As a result, you should define a PopupMenu for the ControlBar that allows the user to turn the toolbars on and off. (See the Delphi IDE for an example.)

Set TControlBar.DragKind to dkDock and TControlBar.DragMode to dmAutomatic to allow the user to drag the ControlBar and all its toolbars off the form. You will need another TControlBar (or another component with DockSite set to true) if you want to be able to place it back in the form. (Do not set DockSite to true on the form itself. I don't like how that works)

In a ControlBar, the ToolBar's handle is two vertical bars and the cursor does not change when you point to it. This "appears" to be what the Delphi IDE uses.

If you also want to have a "menu" toolbar, search the net for TMenuBar. Alternatively, you can configure a toolbar to display a menu.

For more information on docking, see Delphi By Design.


TCoolBar is a Windows component (ie, it is part of the operating system) that provides a location to dock toolbars. When toolbars are included in a coolbar, then those toolbars can not include TEdit components. Instead, each TEdit component becomes its own movable toolbar.

By default, DockSite is set to false. Change this if you want to let the user undock and dock toolbars.

The toolbar handle is a single vertical bar, the cursor changes when you point to the handle.

When testing, I was able to create a situation where one toolbar wrapped on top of another. It was a complete and unusable mess.
(Tested with Delphi 5 on Windows 98)

Developer's Guide

Some of this is in the Delphi Developer's Guide that comes with Delphi 5, and some of it is not.

Author: Robert Clemenzi -
URL: http:// / user / clemenzi / technical / Languages / Delphi / Toolbars.html