【发布时间】:2010-11-26 18:12:04
【问题描述】:
我想在屏幕上的任意位置跟踪鼠标光标的位置,在屏幕坐标中。那么即使鼠标光标移动到了窗口边界之外,有没有办法获取鼠标光标的位置呢?
我正在做的是试图让一个弹出窗口跟随鼠标光标,即使它移出主窗口。
这是我尝试过(但没有奏效)的代码 sn-p:
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.";
}
【问题讨论】:
标签: wpf