【问题标题】:WinForm Hosted in WPF Mouse.getPosition not workingWPF 中托管的 WinForm Mouse.getPosition 不起作用
【发布时间】:2016-11-20 22:47:36
【问题描述】:

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

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

【问题讨论】:

  • 欢迎来到 SO Andre。不要害羞并分享您目前用于获得职位的代码。

标签: c# wpf winforms mouse elementhost


【解决方案1】:

您可以为您的页面窗口使用 MouseMove 事件。让例如 页面窗口为 mainWindow,元素名称为 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....
    }
}

希望这些帮助。

【讨论】:

    猜你喜欢
    • 2012-09-04
    • 2014-07-16
    • 2013-09-17
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    相关资源
    最近更新 更多