TCommonDialog -- TColorDialog
Color Attribute
Corresponding object: TColorDialog
Declaration: property Color: TColor default clBlack;
Function: The Color attribute is used to determine which Color to select in the Color dialog box. When you select a new Color, the Color attribute is set as the new Color value.
Example:
// Change the color of the selected text when the user choose
// Color from the Color dialog box
Procedure TForm1.sbColorClick (Sender: TObject );
Begin
Colordialog1.Execute;
RichEdit1.SelAttributes. Color: = Colordialog1.Color;
End;
CustomColors attributes
Corresponding object: TColorDialog
Declaration: property CustomColors: TStrings;
Function: The CustomColors attribute determines a custom color that can be obtained in the color dialog box. The CustomColors attribute stores a list of strings. The format of each string is ColorX = HexValue. ColorX is one of 16 custom colors, from ColorA to ColorP, the HexValue parameter is a hexadecimal value that represents the RGB value of the color. Therefore, the value corresponding to pure white is FFFFFF, 000000 is pure black, and Color0 = 000000
It indicates that the pure black is passed to the color selection. When the color dialog box is closed, the color list of the dialog box is saved so that you can use custom colors in the next dialog box.
Example:
Procedure TForm1.sbColorClick (Sender: TObject );
Var X: Integer;
Begin
Colordialog1.CustomColers: = StrCustomColors;
Colordialog1.Execute;
RichEdit1.SelAttributes. Color: = Colordialog1.Color;
StrCustomColors: = Colordialog1.CustomColors;
// Save StrCustomColors to the registry or an INI file
// When the program exits...
End;
Options Properties
Corresponding object: TColorDialog
Declaration: TColorDialogOption = (cdFullOpen, cdPreventFullOpen, cdShowHelp, cdSolidColor,
CdAnyColor );
TColorDialogOptions = set of TColorDialogOption;
Property Options: TcolorDialogOptions default [];
Function: The Options attribute describes the display format and Options of the color dialog box.
The following lists valid option values.
Option value
CdFullOpen: the custom color option is displayed when the color dialog box is opened.
CdPreventFullOpen makes the custom color defined in the dialog box unavailable,
Therefore, the user cannot define a new color.
CdShowHelp adds a Help button in the dialog box.
CdSolidColor guides the system to use the latest pure color options.
CdAnyColor allows users to select a non-pure color (which can be subject to approximate jitter)
All options are disabled.
Example:
Procedure TForm1.FormCreate (Sender: TObject );
Begin
ColorDialog1.Options: = [cdFullOpen, cdShowHelp];
End;
OnClose event
Corresponding object: TColorDialog
Declaration: property OnClose: tpolicyevent;
Function: When a dialog box is closed, the OnClose event is triggered. When the dialog box is closed, write a handle of the OnClose event to complete the specified operation.