VCL Controls: Category Buttons |
|
Introduction to the Category Buttons |
Description |
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. |
|
The category buttons control is available from a class named TCategoryButtons, which is defined in the CategoryButtons.pas package. 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. Specify its owner and its parent. Here is an example: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, CategoryButtons, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var SeriesOfButtons : TCategoryButtons; begin SeriesOfButtons := TCategoryButtons.Create(Self); SeriesOfButtons.Parent := Self; end; end.
|
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: procedure TForm1.FormCreate(Sender: TObject); var SeriesOfButtons : TCategoryButtons; begin SeriesOfButtons := TCategoryButtons.Create(Self); SeriesOfButtons.Parent := Self; SeriesOfButtons.Left := 8; SeriesOfButtons.Top := 40 end;
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:
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: property Categories: TButtonCategories read FButtonCategories write SetButtonCategories; 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: procedure TForm1.FormCreate(Sender: TObject); var SeriesOfButtons : TCategoryButtons; Category : TButtonCategory; begin SeriesOfButtons := TCategoryButtons.Create(Self); SeriesOfButtons.Parent := Self; SeriesOfButtons.Left := 8; SeriesOfButtons.Top := 40; Category := SeriesOfButtons.Categories.Add; end; In the same way, you can create as many categories as you want.
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:
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: property Items: TButtonCollection read FItems write SetItems; Each button of a category is of type TButtonItem. To programmatically create a button, you can call the Add() method. This method returns a TButtonItem object. Here is an example: procedure TForm1.FormCreate(Sender: TObject); var SeriesOfButtons : TCategoryButtons; Category : TButtonCategory; btn : TButtonItem; begin SeriesOfButtons := TCategoryButtons.Create(Self); SeriesOfButtons.Parent := Self; SeriesOfButtons.Left := 8; SeriesOfButtons.Top := 40; Category := SeriesOfButtons.Categories.Add; btn := Category.Items.Add(); end; Getting the result of the Add() method, you can set the desired properties of the button.
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: property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle; If you want the control to appear flat, set this property to bsNone. You can do it programmatically as follows: procedure TForm1.FormCreate(Sender: TObject);
var
SeriesOfButtons : TCategoryButtons;
begin
SeriesOfButtons := TCategoryButtons.Create(Self);
SeriesOfButtons.Parent := Self;
SeriesOfButtons.Left := 8;
SeriesOfButtons.Top := 40;
SeriesOfButtons.BorderStyle := bsNone;
end;
To enhance its usefulness, a category buttons control uses various options that are controlled by its ButtonOptions property: property ButtonOptions: TCatButtonOptions read FButtonOptions write SetCatButtonOptions;
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.
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: procedure TForm1.FormCreate(Sender: TObject);
var
SeriesOfButtons : TCategoryButtons;
Category : TButtonCategory;
btn : TButtonItem;
begin
SeriesOfButtons := TCategoryButtons.Create(Self);
SeriesOfButtons.Parent := Self;
SeriesOfButtons.Left := 8;
SeriesOfButtons.Top := 40;
Category := SeriesOfButtons.Categories.Add;
btn := Category.Items.Add();
btn.Caption := 'Set';
end;
Not all buttons have to have captions. In fact, you will decide what button should have a caption and which one doesn't need one.
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: property ButtonWidth: Integer read FButtonWidth write SetButtonWidth; In the same way, to apply the same height to all buttons, assign the desired value to the ButtonHeight property: property ButtonHeight: Integer read FButtonHeight write SetButtonHeight; These values are independent.
When a category has just been created, it is empty and shows only a gradient color. If you add at least one button to a category, that category becomes equipped with a chevron:
To show the contents of a category, the user can click the chevron:
This is referred to as collapsing a category. To support this operation, the TButtonCategory class is equipped with a Boolean property named Collapse: property Collapsed: Boolean read FCollapsed write SetCollapsed; To visually collapse a category, access its Object Inspector, and set the Collapse property to True. To do this programmatically, set the value of Collapse to True. Here is an example: procedure TForm1.FormCreate(Sender: TObject);
var
SeriesOfButtons : TCategoryButtons;
Category : TButtonCategory;
btn : TButtonItem;
begin
SeriesOfButtons := TCategoryButtons.Create(Self);
SeriesOfButtons.Parent := Self;
SeriesOfButtons.Left := 8;
SeriesOfButtons.Top := 40;
Category := SeriesOfButtons.Categories.Add;
btn := Category.Items.Add();
btn.Caption := 'Set';
SeriesOfButtons.Categories[0].Categories[0].Collapsed := True;
end;
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.
To enhance its appearance, a category can be painted with a specific color. This is done using the Color property: property Color: TColor read FColor write SetColor;
Another feature used for aesthetic reasons on a category is to paint it with a fading color. This is done through the GradientColor property: property GradientColor: TColor read FGradientColor write SetGradientColor; Each category uses its own gradient color.
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.
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: property TextColor: TColor read FTextColor write SetTextColor;
Instead of showing captions on button, you can use pictures. To support them, the TCategoryButtons class is equipped with a property named Images : property Images: TCustomImageList read FImages write SetImages; Create an image list that contains the necessary pictures. If you want to use pictures that are larger and/or taller that 16 pixels, you should programmatically create the image list. After creating the image list, assign it to the category buttons control. To specify the image to show on a button, specify its position using the ImageIndex property.
|
|
|||||||||||||||||||||||||||||||||||||||||||||
|
|
||
Home | Copyright © 2010-2016, FunctionX | |
|