我想在屏幕上的任意位置跟踪屏幕坐标中鼠标光标的位置。所以即使鼠标光标移动到窗口边界之外,是否有办法获得鼠标光标的位置?如何将GetMousePosition放置在屏幕上的任何地方,在窗口的边界之外(或任何可视)
我正在做的是试图让弹出窗口跟随鼠标光标,即使它离开主窗口。
这里是什么,我已经尝试了代码片段(和没有工作):
private void OnLoaded(object sender, RoutedEventArgs e)
{
bool gotcapture = this.CaptureMouse();
Mouse.AddLostMouseCaptureHandler(this, this.OnMouseLostCapture);
}
Point mouse_position_relative = Mouse.GetPosition(this);
Point mouse_screen_position = popup.PointToScreen(mouse_position_relative);
private void OnMouseLostCapture(object sender, MouseEventArgs e)
{
bool gotcapture = this.CaptureMouse();
this.textblock.Text = "lost capture.";
}