//To get a point relative to a UI element: private Point GetPointRelativeToElement(UIElement element, Point point) { return element.TranslatePoint(point, element); }
//To get the absolute screen position of a UI element, private Point GetAbsolutePositionOfElement(UIElement element) { return element.PointToScreen(new Point(0, 0)); }
//To get the absolute midpoint of a UI element, private Point GetAbsoluteMidPointOfElement(FrameworkElement element) { Point midPoint = element.TranslatePoint(new Point(element.Width / 2, element.Height / 2), element); Point absolute = PointToScreen(midPoint); return absolute; }
To get the relative and absolute mouse position,
private Point GetAbsoluteMousePosition() { return PointToScreen(Mouse.GetPosition(this)); } private Point GetMousePositionRelativeToElement(UIElement element) { return Mouse.GetPosition(element); }
//To programmatically adjust mouse position, using System.Runtime.InteropServices; [DllImport("user32.dll")] static extern bool SetCursorPos(int X, int Y);