Back

Have you ever wondered how they fill those little boxes in a TColorDialog with colours(Colors)? Here is how it is done.

Drop the TColorDialog on a Form (Form1).
In the Object Inspector for the ColorDialog doubleclick on 'Custom Colors' (TStrings).
This will open the 'String list editor'.

Paste these lines into the String list editor.

ColorE=EABCCA
ColorF=FBBCCA
ColorG=ACBBCA
ColorH=BDBCCA
ColorI=DEBCCA
ColorJ=EFBCCA
ColorK=BBBAAA
ColorL=DDDAAA
ColorM=EEEAAA
ColorN=ABCDEF
ColorO=FEDCBA
ColorP=CDBEFA

Click 'OK' to save your changes to the String list editor .

Drop Shape1 (TShape) on Form1.
Drop a Button on Form1.
DoubleClick on the Button and type this code.

 if ColorDialog1.Execute then
   begin
       Shape1.Brush.Color := ColorDialog1.Color;
   end;

Run the program, click on the button, click on a colour
and Shape1 will change to that colour.
Notice you will have many new colours available to choose from.


Back