Lazarus

Programming => General => Topic started by: Davidous on June 24, 2019, 09:57:08 pm

Title: Title/footer click tool
Post by: Davidous on June 24, 2019, 09:57:08 pm
Hello,

I found a short description about Title/footer click tool, but I don't know how to use it.
Where can I get it from? I would like to make an OnClick event when I click on the chart title.
Title: Re: Title/footer click tool
Post by: wp on June 24, 2019, 10:48:06 pm
PLEASE: Add something like "Chart" or "TAChart" to the title of the post, or better: post the question in the TAChart sub-board. Otherwise there's a high risk that the question is left unnoticed.

Add a TChartToolset component to the form (the one with the red wrench icon) and assign it to the "Toolset" property of the chart. Double click on it and add a "Header/footer click" tool. Select a "Shift" item with which the user can activate the tool. Now you have the OnClick event which fires when the header oder footer of the chart is clicked.

Since this is a very recent feature you need Lazarus trunk.
Title: Re: Title/footer click tool
Post by: jamie on June 25, 2019, 02:12:39 am
Needs a little refinement but here goes.

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.Chart1Click(Sender: TObject);
  3. Var
  4.   P:TPoint;
  5.   R:TRect;
  6. begin
  7.   R  := Rect(0,0,Chart1.Width, Chart1.Canvas.TextExtent(Chart1.Title.Text.text).cy);
  8.   P := Chart1.ScreenToClient(Mouse.CurSorPos);
  9.   If PtInRect(R, P) Then Beep;
  10. end;                            
  11.  

Place your pointer on the text in the header and Click!
Title: Re: Title/footer click tool
Post by: wp on June 25, 2019, 10:00:52 am
This code is too simple, it does not respect the true position of the title which may be left-, center- or right-aligned, and the title may have a font different from that of the chart's Canvas which makes the height calculation wrong.
TinyPortal © 2005-2018