Lazarus

Programming => General => Topic started by: DenPit5 on December 07, 2018, 01:13:51 pm

Title: Detecting Click on a Form.
Post by: DenPit5 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 !!
Title: Re: Detecting Click on a Form.
Post by: BSaidus 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.  
Title: Re: Detecting Click on a Form.
Post by: sash 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;
TinyPortal © 2005-2018