A category button is a control container that uses one
or more sections. Each section holds one (rectangular) button or a group
of (rectangular) buttons. In fact, each section is constructed like a
button group. Besides being able to hold more than one group of buttons,
one of the differences between a button group and a category button is
that the group of buttons in a category button can be minimized or
collapsed. That is, the user can hide the buttons of a particular group
and keep the button(s) of the other series visible.

Practical
Learning: Introducing Category Buttons

To start a new application, on the main menu, click File -> New ->
VCL Forms Application - C++Builder

In the Object Inspector, change the properties of the form as
follows:Caption: Geometric Shapes
Name: frmGeometryPosition:
poScreenCenter

To save the project, on the Standard toolbar, click the Save All
button

Click the New Folder button

Type GeometricShapes1 as the name of the folder and
press Enter twice to display its content

Type Geometry as the name of the unit and press
Enter

Type GeometricShapes as the name of the project and
press Enter

Press F9 to test the project

Close the form

Copy each one of these images and paste it in the Debug folder of
this project:

Return to your programming environment

Creating a Category Buttons Control

The category buttons control is available from a class
named TCategoryButtons, which is defined in the
CategoryButtons.hpp header file. The TCategoryButtons class is
derived from TCustomControl that is based on TWinControl:

To visually create a category buttons
control, in the Additional section of the Tool Palette, click the
TCategoryButtons icon
and click the form. To programmatically create a category buttons control,
declare a variable of type TCategoryButtons. Use the
new operator to initialize it and specify its owner. Also
make sure you specify its parent. Here is an example:

A category buttons control is a Windows control. It gets
its foundational characteristics from the TWinControl and
the TControl classes. For this reason, in must have a name,
a location, and a size. Here is an example of applying some of these
features:

A category buttons controls if primarily one button
group or a series of button groups. This means that, to make a buttons group
control available in your application, the first thing you must do is to
create one or more button groups.

To visually create a category, right-click the category
buttons control and click Category Editor:

This would open the Editing Category Buttons Category
window:

To create a category:

Click the New button

Right-click the window and click Add

Press Ins

This would create one category. In the same way, you can
create as many categories as necessary. By default, each new category
appears a horizontal bar that uses the whole width of the category buttons
control.

To hold its series, the TCategoryButtons
class is equipped with a property named Categories. The
TCategoryButtons::Categories property is an indexed
property based on a class named TButtonCategories:

The TButtonCategories class is derived from
TItemCollection that itself is based on the TCollection
class.

Each member of the TButtonCategories class is of
type TButtonCategory. The TButtonCategory class is derived
from TBaseItem, which is the parent of the TCollectionItem
class. Based on this, to programmatically create a category, you can call
the Add() method that the TCategoryButtons
class inherits from TCollection. The
TButtonCategories::Add() method returns a TButtonCategory
object. When calling the Add() method, you should make sure
you get this returned value so you can use it later. Here is an example:

Normally, a category appears as an empty colored bar. To
make it useful, it must contain one or more buttons. To visually create the
buttons of a category, in the Editing Category Buttons Categories, click the
category. Then, in the Object Inspector, click Items and click its button.
This would open the Editing Category Buttons Items window. To visually
create a button:

Click the New button

Right-click the window and click Add

Press Ins

Any of these actions would create a new button.

As mentioned already, a/each category should contain at
least one button. The buttons of a category are represented in the
TButtonCategory class by a property named Items, which
is an indexed property that contains TButtonCollection
items:

Right-click the Editing Category Buttons Items window and click Add
4 times to get 5 buttons

Save all

The Border Style

A category buttons control uses some of the same
characteristics as the button group. A category buttons control appears with
a 3-D border. This characteristic is set by the BorderStyle
property that is of type TFormBorderStyle:

If you want the user to be able to modify the order of
the buttons in the categories, set the gboAllowReorder
member of the ButtonOptions value to True. Then, to order
the buttons, the user can click and drag a button to drop it in a different
position.

The Buttons' Captions

A button can be made to show a caption. This is possible
because each button has a Caption property. To make sure
the buttons can show captions, you must set the gboShowCaptions
member of the ButtonOptions value to True. Then, assign the
desired caption to a button. Here is an example:

Not all buttons have to have captions. You will decide
what button should have a caption and which one doesn't need one.

The Common Size of the Buttons

The buttons of a category use a common size. They can
have the same width and/or the same height. To set a common size to all
buttons, set the gboFullSize member of the
ButtonOptions value to True. Then set the common width using the
ButtonWidth property:

When a category's content is hidden, to reveal it, the
user can click the category itself (or its chevron). This is referred to
expanding the category. To expand a category, set its Collapse
property to False.

The Background Color of a Category

To enhance its appearance, a category can be painted
with a specific color. This is done using the Color
property:

In the Object Inspector, click GradientColor, click the arrow of its
box, and select clWindow

Save all

The Caption of a Category

By default, when a category is collapsed, it shows an
empty bar. If you want, you can make it display a string. This is possible
because the TButtonCategory class is equipped with a
Caption property. If you set a value to this property, when
the category is expanded, the caption or part of it would show under the
chevron. If the caption is made of a letter or a symbol, it would appear
fine. If the caption is too long for the height, only part of it would show.
If you want the whole caption to show, you can change the
ButtonHeight value.

When the category is collapsed, the caption would show
on the right side of the chevron.

Close the Editing Category Buttons Category window but leave the
other windows open

Save all

The Caption Color

If the color of the captions is close to, or the same
as, the background color of the categories, the caption may be difficult to
see. To let you change the caption color, you can use the TextColor
property: