Recent

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

DenPit5

  • New Member
  • *
  • Posts: 21
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

  • Hero Member
  • *****
  • Posts: 540
  • 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

  • Sr. Member
  • ****
  • Posts: 366
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 2.0.10 FPC 3.2.0 x86_64-linux-gtk2 @ Ubuntu 20.04 XFCE

 

TinyPortal © 2005-2018