我想在屏幕上的任意位置跟蹤屏幕座標中鼠標光標的位置。所以即使鼠標光標移動到窗口邊界之外,是否有辦法獲得鼠標光標的位置?如何將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.";
}