Issue with OnClickLegend

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
rackerson
Newbie
Newbie
Posts: 22
Joined: Mon Mar 08, 2004 5:00 am
Location: Edison, New Jersey USA

Issue with OnClickLegend

Post by rackerson » Tue Jan 23, 2007 3:50 pm

I am using Delphi 6 Enterprise and TeeChart Pro 7.07.

We allow the user to perform customization options on the chart legend by intercepting a mouse click in the chart's OnClickLegend event. Overall, this works fine. Anytime the user clicks on the legend contents the event fires and we execute our code.

However, if the Legend Title is visible and the user clicks on the Title, the chart's OnClickLegend event does NOT fire. We would like the same logic to work for us whether the user clicks on the legend items, the legend background, or the legend title. Is there a way to make the OnClickLegend event recognize that the legend's title was clicked?

Thanks

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Jan 23, 2007 4:05 pm

Hi rackerson,

Yes, you can achieve that using something like this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  TitleClicked:=false;
end;

procedure TForm1.Chart1ClickLegend(Sender: TCustomChart;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if not TitleClicked then
    Chart1.Title.Text.Add(IntToStr(Chart1.Legend.Clicked(X,Y)))
  else
    Chart1.Title.Text.Add('Legend title clicked');
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if ((Chart1.Legend.Clicked(X,Y) = -1) and
    (PtInRect(Chart1.Legend.RectLegend,Point(X,Y)))) then
  begin
    TitleClicked:=true;
    Chart1ClickLegend(TCustomChart(Chart1),Button,Shift,X,Y);
  end
  else TitleClicked:=false;
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

rackerson
Newbie
Newbie
Posts: 22
Joined: Mon Mar 08, 2004 5:00 am
Location: Edison, New Jersey USA

Post by rackerson » Tue Jan 23, 2007 5:22 pm

Works perfect! Thanks a lot.

Post Reply