User:Cristina.sirbu/ColorBoxStyle

From RAD Studio
Jump to: navigation, search

Description

Select the File > New > VCL Forms Application - Delphi.

Drag and drop on the form from the 'ToolPalette' a TColorBox and a TComboBox. Than double click on the form and it will switch to code editor at the FormCreate procedure.

Code

procedure TForm2.FormCreate(Sender: TObject);
begin
  //ComboBox options
  ComboBox1.AddItem('cbStandardColors',nil);
  ComboBox1.AddItem('cbExtendedColors',nil);
  ComboBox1.AddItem('cbSystemColors',nil);
  ComboBox1.AddItem('cbIncludeNone',nil);
  ComboBox1.AddItem('cbIncludeDefault',nil);
  ComboBox1.AddItem('cbCustomColor',nil);
  ComboBox1.AddItem('cbPrettyNames',nil);
end;

Switch back to Design view and select the combobox. In the Object Inspector click on the Events tab and then double click on OnChange event handler and insert this code into the ComboBox1Change procedure:

procedure TForm2.ComboBox1Change(Sender: TObject);
begin
 //Switch on the correspondent values of the set 'TColorBoxStyle'
  if ComboBox1.ItemIndex = 0 then
    ColorBox1.Style := [cbStandardColors];
  if ComboBox1.ItemIndex = 1 then
    ColorBox1.Style := [cbExtendedColors];
  if ComboBox1.ItemIndex = 2 then
    ColorBox1.Style := [cbSystemColors];
  if ComboBox1.ItemIndex = 3 then
    //This option only has an effect if Style includes cbSystemColors.
    ColorBox1.Style := [cbSystemColors,cbIncludeNone];
  if ComboBox1.ItemIndex = 4 then
    //This option only has an effect if Style includes cbSystemColors.
    ColorBox1.Style := [cbSystemColors,cbIncludeDefault];
  if ComboBox1.ItemIndex = 5 then
    ColorBox1.Style := [cbCustomColor];
  if ComboBox1.ItemIndex = 6 then
    // This option only has an effect if Style includes another style.
    ColorBox1.Style := [cbStandardColors,cbPrettyNames];end;

Note: This program uses TColorBoxStyle which is a set, instead of TColorBoxStyles which is an enumeration.

Uses