Gets the position of the mouse relative to a specified element.
Assembly: PresentationCore (in PresentationCore.dll)
- Type: System.Windows::IInputElement
The coordinate space in which to calculate the position of the mouse.
Return ValueType: System.Windows::Point
The 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 . 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:
The following example shows how to use to determine the position of the mouse pointer. The position of the mouse pointer is stored in a Point structure. The X and Y values of the Point object are displayed in a TextBox.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2