vcl-153004-expresseditors-task-based-help-tcxcolorcombobox-creating-custom-color-editing-dialogs.md
Color combo boxes (TcxColorComboBox and TcxDBColorComboBox controls) can be customized so that end-users are capable of selecting custom colors. To do this, the Properties.AllowSelectColor property must be set to True. In this instance, the editor displays an ellipsis button that invokes the standard or advanced color editor dialog. You may, however, want to provide a custom color editor dialog instead so as to change the appearance of the dialog or use a new dialog to restrict user input to a predefined range of colors.
To implement a custom color editor dialog for color combo boxes, you need to set the Properties.ColorDialogType property to cxcdtCustom. In this instance, the standard or advanced color editor dialog is not invoked when clicking the ellipsis button. Button clicks invoke the OnSelectCustomColor event. You need to handle this event to display your custom color editor dialog manually. This topic describes how to do this.
The example in this topic will create an application with two forms. One form will contain the color combo box control. Another form will provide a custom color editor dialog. It will allow users to select shades of blue. The TcxTrackBar control will be used to adjust the intensity of the blue channel. The color editor dialog will look as displayed below:
Follow the steps listed below to create the application.
type
TForm2 = class(TForm)
// ...
public
ColorAccepted: Boolean;
// ...
procedure TForm2.btnOkClick(Sender: TObject);
begin
ColorAccepted := True;
Close;
end;
procedure TForm2.btnCancelClick(Sender: TObject);
begin
Close;
end;
type
TForm2 = class(TForm)
// ...
public
function GetColorByThumbPosition: TColor;
// ...
function TForm2.GetColorByThumbPosition: TColor;
begin
Result := $10100 * cxTrackBar1.Position + $FF;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
ColorAccepted := False;
cxGroupBox1.Color := GetColorByThumbPosition;
end;
procedure TForm2.cxTrackBar1Click(Sender: TObject);
begin
cxGroupBox1.Color := GetColorByThumbPosition;
end;
procedure TForm1.cxColorComboBox1PropertiesSelectCustomColor(
Sender: TObject; var AColor: TColor; var AColorDescription: string;
var AddToList: Boolean);
var frmEditor: TForm2;
begin
frmEditor := TForm2.Create(Application);
frmEditor.ShowModal;
AColor := frmEditor.GetColorByThumbPosition;
AddToList := frmEditor.ColorAccepted;
end;
See Also
TcxCustomColorComboBoxProperties.AllowSelectColor