鼠标 控件 位置 关系

//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);

posted on 2011-11-11 19:34  Y#  阅读(171)  评论(0)    收藏  举报

导航