Mouse::GetPosition Method (IInputElement^)
Gets the position of the mouse relative to a specified element.
Assembly: PresentationCore (in PresentationCore.dll)
Parameters
- relativeTo
-
Type:
System.Windows::IInputElement^
The coordinate space in which to calculate the position of the mouse.
Return Value
Type: System.Windows::PointThe position of the mouse relative to the parameter relativeTo.
The position of the mouse pointer is calculated relative to the specified element with the upper-left corner of element being the point of origin, 0,0.
During drag-and-drop operations, the position of the mouse cannot be reliably determined through GetPosition. This is because control of the mouse (possibly including capture) is held by the originating element of the drag until the drop is completed, with much of the behavior controlled by underlying Win32 calls. Try the following approaches instead:
Call the GetPosition method of the DragEventArgs that is passed to the drag events (DragEnter, DragOver, DragLeave).
Call GetCursorPos, using P/Invoke.
Available since 3.0