WPF Mouse.getPosition 中托管的 WinForm 无法正常工作

WinForm Hosted in WPF Mouse.getPosition not working

我在 wpf Window 中托管了一些元素 (ZedGraph)。 我想获取鼠标光标的 x 和 y 坐标。 它适用于 window 的其余部分,但只要我将鼠标悬停在 Elementhost 上,数字就会被冻结。 我已经发现 Elementhost 没有传递事件,但我没有找到解决该问题的有效方法。

非常感谢有关该问题的任何提示

您可以为您的 页面 window 使用 MouseMove 事件。让例如名称 Page window 是 mainWindow,Element 的名称是 myElement1。然后你可以得到 元素的 X-Y 位置,并将其用于与鼠标位置 X-Y 的比较,如以下示例所示,

private void mainWindow_MouseMove(object sender, MouseEventArgs e)
{
    System.Windows.Point thepnt = new System.Windows.Point();

    thepnt = e.GetPosition(myElement1);
    if (((thepnt.X<=100)|| (thepnt.X > myElement1.Width)) || (thepnt.Y < 100))
    {
       //do something...
    }
    else
    {
       //do something else....
    }
}

希望这些帮助。