The TCoolBar component is a type of TToolBar. TCoolBar component is a container control that typically contains two or more TCoolBands which may be resized and rearranged by the user at run time.
A CoolBand is a region of the control that can contain other windowed controls, mostly toolbars, edit boxes, combo boxes and animations.
Creating a coolbar is simple: just drop a CoolBar component from the Win32 VCL palette onto a form. We can customize the CoolBar component in many ways (through it's properties): Bitmap - can be used to paint CoolBar's background with a bitmap picture; FixedOrder property determines whether users can reorder the bands.
TCoolBandThe Coolbar component is basically a collection of TCoolBand objects. To add some CoolBand's to the CoolBar we have to invoke the Coolbar Bands Editor, by clicking the ellipsis next to the CoolBar's Bands property.
One way to place a component (or a component container) on a CoolBar is to drop it from the VCL palette, this automatically creates a new band to hold the component. Another way is to insert the component directly into a form, then use the CoolBar Bands Editor to assign it to some of the CoolBands.
Placing Control on a Cool BandThe typical component used in a CoolBar is the Toolbar, which is basically a panel with bunch of buttons on it. To add a Toolbar component (Win32 palette) simply drop one onto the Coolbar. After that add one or more buttons to the toolbar and work with the toolbar as you normally do.
The most interesting features of the CoolBar component is the fact that it can contain controls other that buttons (that is toolbars).
Let's drop a combo box, an edit box and one animation to the CoolBar. Suppose we have a memo component on a form with some text in it. We can, for example, use the edit control to set the size of the font, combo box to set the font used to display the text in a memo and animate control as an indication that something is happening in a program.
At run time, the user positions the controls by dragging the sizing grip to the left of each band.
More Controls for a Cool Bar...
As mentioned, we can add any windowed component on a CoolBar. Windowed components are those derived from TWinControl. This means that Labels and Shapes, for example, can't be placed on a CoolBar. However, if we take a look at the Delphi IDE we'll see that a coolbar can also host a menu with menu items. Since menus are not windowed components there must be some way to place them on a cool band!
Cool Menus on Cool Bands
The trick to put the application's menu on a CoolBar is to use the ToolBar component.
First we have to place a MainMenu component on a form and use the Menu designer to add menu items to it. Note that when we place a TMainMenu component on a form, the value of the form's Menu property is set to MainMenu1. We have to clear this property to disconnect the MainMenu object from the form, since we want to use it in a Coolbar. Second, add a Toolbar to a Coolbar and add few ToolButtons, one ToolButton for every pull-down menu. If you, for example, have a File and Edit top level menu items add two ToolButtons.
Next, set the properties of a toolbar. Set Flat and ShowCaptions to True. AutoSize and Grouped properties of ToolButtons should be also set to True. And finally connect each tool button with the correct pull down menu using the MenuItem property.
Cool CodingThe code below adds a CoolBand to a CoolBar with a TDateTimePicker on it, at run time.
Note: By using the "CoolBar1.Bands.Items[count - 1]" we get the reference of the last TCoolBand created to assign text to it. Note2: The memory for a TDateTimePicker component is automatically freed when its owner's memory is freed, that is when the application ends and the CoolBar is destroyed by the form.
procedure CreateDatePickerOnCoolBar; var dtPick: TDateTimePicker; begin dtPick := TDateTimePicker.Create(CoolBar1) ; dtPick.Parent := CoolBar1; CoolBar1.Bands.Items[Count-1].Text := 'Pick a date'; ... end;
The CreateDatePickerOnCoolBar procedure only creates a TDateTimePicker on a CoolBar, to use TDateTimePicker events, we have to provide one or more event handling procedures.
At the end of the CreateDatePickerOnCoolBar procedure add
OnCloseUp occures when the drop-down calendar closes. We'll use this event to pass a date from DateTimePicker to a Memo component:
dtPick.OnCloseUp := dtpOnCloseUp;