0

I have some element (ZedGraph) hosted in a wpf Window. I want to get the x and the y coordinate of my mousecursor. It works on the rest of the window but as soon as I hover over the Elementhost the numbers are frozen. I already found out that Elementhost does not pass the events, but I dont found a working solution to that Problem.

many thanks in advance for any hints on that problem

4

1 回答 1

0

您可以为Page 窗口使用 MouseMove 事件。例如,页面窗口的名称为 mainWindow,元素的名称为 myElement1。然后您可以获取元素的位置 XY 并将其与鼠标位置 XY 进行比较,如下例所示,

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....
    }
}

希望这些帮助。

于 2016-11-21T00:22:15.733 回答