Page 1 of 1

Issue with OnClickLegend

Posted: Tue Jan 23, 2007 3:50 pm
by 9336044
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

Posted: Tue Jan 23, 2007 4:05 pm
by narcis
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;

Posted: Tue Jan 23, 2007 5:22 pm
by 9336044
Works perfect! Thanks a lot.