Add Custom Colors to TColorButton color dialog

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
odissey1
Newbie
Newbie
Posts: 35
Joined: Thu Oct 23, 2003 4:00 am

Add Custom Colors to TColorButton color dialog

Post by odissey1 » Mon Feb 01, 2010 12:44 am

Hi,
I want to add custom colors to the color dialog , which appears when TColorButton is clicked. Is there any possibility to add a 'custom color string' to the TeeChart application?

Sincerely,
odissey1
TC8.02 Pro +Source/D2007

odissey1
Newbie
Newbie
Posts: 35
Joined: Thu Oct 23, 2003 4:00 am

Re: Add Custom Colors to TColorButton color dialog

Post by odissey1 » Mon Feb 01, 2010 4:12 am

Here is some solution:

Code: Select all


//add TColorDialod component on the form and define custom colors in it

uses ..., TeCanvas;

procedure TForm1.FormCreate(Sender: TObject);
begin
       TeeCustomEditColors:=TStringList.Create;
       TeeCustomEditColors.Assign(ColorDialog1.CustomColors);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
       TeeCustomEditColors:=nil; //must set to nil else Err
//       TeeCustomEditColors.Free;//Err - do not free here
end;



Wishlist: it would have been nice if underlying TColorDialog in TButtonColor was published.

Any other approaches?

Regards,
odissey1

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Add Custom Colors to TColorButton color dialog

Post by Yeray » Tue Feb 02, 2010 4:42 pm

Hi odissey1,

I'm not sure to understand what are you exactly trying to achieve. Do you have a list of colors you want to be shown in the below part of the series' color picker window? O do you want to overwrite the whole color picker window?

Could you please send us a simple example project we can run as-is here showing us the solution you proposed?

Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

odissey1
Newbie
Newbie
Posts: 35
Joined: Thu Oct 23, 2003 4:00 am

Re: Add Custom Colors to TColorButton color dialog

Post by odissey1 » Tue Feb 02, 2010 5:43 pm

Hi Yeray,

>Do you have a list of colors you want to be shown in the below part of the series' color picker window?
-Yes. Please see image attached. The code above was used with TC v7.12
odissey1
Attachments
PenDraw_05.jpg
TButtonColor dialog with pre-defined custom colors
PenDraw_05.jpg (89.87 KiB) Viewed 15344 times

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Add Custom Colors to TColorButton color dialog

Post by Yeray » Wed Feb 03, 2010 8:54 am

Hi odissey1,

Here is an example of what I understood you are trying to do:

Code: Select all

uses series;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TBarSeries.Create(self));
  Chart1[0].FillSampleValues();
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TColorDialog.Create(self) do
  begin
    CustomColors.Add('ColorA=808022');
    CustomColors.Add('ColorI=408090');
    Execute;
    Chart1[0].Color:=Color;
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

odissey1
Newbie
Newbie
Posts: 35
Joined: Thu Oct 23, 2003 4:00 am

Re: Add Custom Colors to TColorButton color dialog

Post by odissey1 » Wed Feb 03, 2010 6:23 pm

Hi Yeray,
I have no problem adding colors to the standard TColorDialog. The one you see on the picture is an internal TColorDialog from TButtonColor, which is a TeeChart component (lime color button on top of the form). The problem is that this color dialog is not public neither published, so there is no regular access to it. The fix I posted above gives access to TCustomColorString inside TeCanvas unit, but this is not nice way to do it. I hope that Steema can change this internal TColorDialog to published, so it could be edited at design time.
odissey1

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Add Custom Colors to TColorButton color dialog

Post by Yeray » Thu Feb 04, 2010 10:25 am

Hi odissey1,

Ok, I think now I understand your situation. And yes, for some situations your request could be useful. I've added it to the wish list to be implemented in future releases (TV52014664).

In the meanwhile you could use TButtons (with a TEdit without text, but color) with the standard TColorDialog. Something as follows:

Code: Select all

uses series;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TBarSeries.Create(self));
  Chart1[0].FillSampleValues();

  Edit1.Text:='';
  Edit1.Color:=chart1[0].Color;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TColorDialog.Create(self) do
  begin
    CustomColors.Add('ColorA=808022');
    CustomColors.Add('ColorI=408090');
    CustomColors.Add(ColorToString(Edit1.Color));
    if Execute then
    begin
      Chart1[0].Color:=Color;
      Edit1.Color:=Color;
    end;
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply