Navigation: TextEd > Extension and Scripts > Dialogs >






TColorDialog displays a modal color-selection dialog.


The TColorDialog component displays a Windows dialog box for selecting colors. The dialog does not appear at runtime until it is activated by a call to the Execute method. When the user selects a color and clicks OK, the dialog closes and the selected color is stored in the Color property.


Properties and methods


constructor Create(TComponent AOwner);

Creates and initializes a color-selection dialog.



TColorDialog clDlg = TColorDialog.Create(form);


function bool Execute;

Displays the dialog box. Execute returns true when the user makes a selection and clicks OK, and returns false when the user closes the dialog without making a selection.



TColorDialog clDlg = TColorDialog.Create(form);

clDlg.Color = clGreen;

if (clDlg.Execute) {

   panel.Color = clDlg.Color;




procedure Free;

Destroys an object and frees its associated memory, if necessary.


property TColor Color;

Returns the selected color. When the user selects a color in the dialog box and clicks OK, the selected color becomes the value of the Color property. To make a default color of choice appear in the dialog when it opens, assign a value to Color.




TForm f;
TButton b;
// Open a color dialog and change
// the form background color to
// the selected color.
void btnClick(TObject Sender) {
   TColorDialog colorDlg = TColorDialog.Create(f);
   colorDlg.Color = clGreen;
   if (colorDlg.Execute) {
      f.Color = colorDlg.Color;
// Main procedure
   // Create a new window (form)
   f = new TForm(nil);
   f.Caption = "Change window color";
   f.Position = poScreenCenter;
   f.Width = 200;
   f.Height = 100;
   // Add a button to the window
   b = new TButton(f);
   b.Name = "btnColor";
   b.Parent = f;
   b.SetBounds(20, 50, 75, 25);
   b.Anchors = akLeft+akTop;
   b.Caption = "Color...";
   // When the user click on the button the 
   // function btnClick is executed
   b.OnClick = &btnClick; 
   // Show the window








Copyright © 2023 Rickard Johansson