Vcl.ExtCtrls.TCustomColorBox.OnGetColors
Delphi
property OnGetColors: TGetColorsEvent read FOnGetColors write FOnGetColors;
C++
__property TGetColorsEvent OnGetColors = {read=FOnGetColors, write=FOnGetColors};
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
event | public | Vcl.ExtCtrls.pas Vcl.ExtCtrls.hpp |
Vcl.ExtCtrls | TCustomColorBox |
Description
Occurs when the control is populated with a customized list of colors.
Use OnGetColors to populate a customized list of colors to be placed in the TCustomColorBox colors list.
The OnGetColors event is only called when Style includes the cbCustomColors property.
- Sender is the instance of the TCustomColorBox.
- Items is a TStrings containing a list of colors displayed in the TCustomColorBox.
- Items.Strings contains the list of display strings for the color box.
- Items.Objects contains the list of TColor values corresponding to each display name (Items.Strings), cast as a TObject.
- Note: When this event is raised, Items contains all of the colors that are specified in the Style property, such as cbStandard. Colors are added, moved, or removed from the TCustomColorBox by manipulating this Items list.
Code Snippets
To clarify, the following code snippet adds three custom colors to the drop-down list of colors. Consider the following scenario: an application has a TColorBox and the cbCustomColors is set to True (in the Style property).
In this scenario, you can implement the following OnGetColors event handler:
Delphi:
procedure TForm1.ColorBox1GetColors(Sender: TCustomColorBox; Items: TStrings);
begin
Items.AddObject('Custom Black', TObject(clBlack));
Items.AddObject('Custom White', TObject(clWhite));
Items.AddObject('Custom Red', TObject(clRed));
end;
C++Builder:
void __fastcall TForm1::ColorBox1GetColors(TCustomColorBox *Sender, TStrings *Items)
{
Items->Clear();
Items->AddObject("Custom Black", (TObject*) (clBlack));
Items->AddObject("Custom White", (TObject*) (clWhite));
Items->AddObject("Custom Red", (TObject*) (clRed));
}