Recent

Author Topic: Detecting Click on a Form.  (Read 147 times)

DenPit5

  • New member
  • *
  • Posts: 8
Detecting Click on a Form.
« on: December 07, 2018, 01:13:51 pm »
I need to be able to click on a Form and get the x & y coordinates of a click.   I realise they must be somehow available in the ONClick event but don't know how they are presented there.    Can Anyone Help. ?? Please !!

BSaidus

  • Sr. Member
  • ****
  • Posts: 250
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: Detecting Click on a Form.
« Reply #1 on: December 07, 2018, 01:21:11 pm »
Use the OnMouseDowne event that contain X and Y coordinate.

Code: Pascal  [Select]
  1. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. begin
  4.  
  5. end;
  6.  
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

sash

  • Full Member
  • ***
  • Posts: 158
Re: Detecting Click on a Form.
« Reply #2 on: December 07, 2018, 02:40:45 pm »
Also available as @Mouse.CursorPos@ anywhere in Application.

Code: Pascal  [Select]
  1. procedure TForm1.FormClick(Sender : TObject);
  2. var
  3.   mp : TPoint;
  4. begin
  5.   mp := Mouse.CursorPos; //in screen coordinates
  6.   mp := {AnyControl.}ScreenToClient(Mouse.CursorPos); //in form (or any other control coordinates)
  7.   ShowMessageFmt('click: [%d:%d]', [mp.x, mp.y]);
  8. end;
Lazarus 1.8.4 Unversioned directory FPC 3.0.4 x86_64-linux-gtk2 -- Ubuntu 18.04 XFCE