Page 1 of 1

Legend Checkbox left click not working, right click ok

Posted: Mon Jan 25, 2010 3:36 pm
by 10054230
Folks,
For some reason my left click event in a Legend check box is no longer working. The right click and middle click works fine and triggers an OnClickLegend event successfully. I'm very confused as it was working previously. My legend position is drawn at a CustomPosition=true. I may be doing something stupid but please help.

Regards,
D'Arcy.

Re: Legend Checkbox left click not working, right click ok

Posted: Mon Jan 25, 2010 4:24 pm
by yeray
Hi D'Arcy,

I'm not able to reproduce it here with the following code:

Code: Select all

procedure TForm1.Chart1ClickLegend(Sender: TCustomChart; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ShowMessage('legend clicked!');
end;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i := 0 to 9 do
  begin
    Chart1.AddSeries(TLineSeries.Create(self));
    Chart1[i].FillSampleValues();
  end;

  Chart1.Legend.CheckBoxes:=true;
  Chart1.Legend.CustomPosition:=true;
  Chart1.Legend.Left:=100;
  Chart1.Legend.Top:=50;
end;
Could you please modify it so we can reproduce it here (or send us a simple example project we can run as-is to reproduce the problem here)?

Re: Legend Checkbox left click not working, right click ok

Posted: Tue Jan 26, 2010 10:35 am
by 10054230
Hi Yeray,
Problem sorted. Thanks for the example. When I created a clean example the legend click worked fine (left, middle, right click). Therefore it was local to my application. One for your records, when the TDrawLineTool is added it can take control of the left click. Guess it was due to the left click and drag functionality being enabled by default within the tool which took precedence of the left click event. Only when I removed this did it re-enable the left click for the legend.

Thanks for the help.

Regards,
D'Arcy

Re: Legend Checkbox left click not working, right click ok

Posted: Tue Jan 26, 2010 1:16 pm
by 10050769
Hello darcy,

I found a simple solution that I think solve your problem. Please check next code works correctly.

Code: Select all

var ChartTool1: TDrawLineTool;
procedure TForm1.Chart1ClickLegend(Sender: TCustomChart; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ShowMessage('legend clicked!');
end;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  ChartTool1 := TDrawLineTool.Create(Self);
  Chart1.Tools.Add(ChartTool1) ;
  for i := 0 to 9 do
  begin
    Chart1.AddSeries(TLineSeries.Create(self));
    Chart1[i].FillSampleValues();
  end;
  Chart1.Legend.CheckBoxes:=true;
  Chart1.Legend.CustomPosition:=true;
  Chart1.Legend.Left:=100;
  Chart1.Legend.Top:=50;
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
 Shift: TShiftState; X, Y: Integer);
begin
  ChartTool1.EnableDraw:=not PtInRect(Chart1.Legend.RectLegend,Point(X,Y));
end;
I hope will help.

Thanks,