I need to know the mouse position with relative coordinates to a ListView control in the OnItemClickEx
event. In a multidisplay system, it works for the app showing in the primary monitor, but does not work when the app is showing for the secondary or third monitor.
The code to know the mouse position is the following:
...
var point : TPointF;
...
point := Screen.MousePos;
point := self.ScreenToClient(point): //we obtain wrong local coordinates for the secondary and third monitor with or without this line
point := ListView.AbsoluteToLocal(point);
What is the correct way to know the mouse cursor coordinates relative to a control (in this use case a TListView
)?
UPDATE
In this example you can see that it works fine in the first Form, but in the embedded form it provides wrong coordinates. It was tested in 10.2 and 10.3 with the same results.
Finally, after doing some research and tests I've found the trick:
...
var point : TPointF;
...
point := Screen.MousePos;
point := Application.MainForm.ScreenToClient(point); // The calculation should be with the MainForm, not the embedded!!!
point := ListView.AbsoluteToLocal(point);