Winform ElementHost 中的 MouseEnter 事件 [英] MouseEnter event in Winform ElementHost

查看:40
本文介绍了Winform ElementHost 中的 MouseEnter 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 elementHost 的 Winform,其中包含一个 WPF UserControl.我需要的是当鼠标进入 elementHost 而不是孩子时做一些事情.我试图在 elementHost 中使用 MouseEnter 事件,但它不存在.我有机会做到这一点吗?或者只是不可能?奇怪的是它们上面没有鼠标事件.

I have a Winform with an elementHost in it to contain a WPF UserControl. What I need, is to do something when the mouse enters the elementHost, not the child. I was trying to use MouseEnter event in the elementHost but it does not exists. Is there any chance I can do this? Or is it just not possible? It´s curious to not have mouse events on them.

这是我所有的事件:

如果我想以编程方式进行,我只是没有任何 MouseEvent:

And if I want to do it programatically I just dont have any MouseEvent:

推荐答案

MouseEnter 事件位于 elementHost 的 HostContainer 中,为了检测鼠标何时进入尝试以下代码:

MouseEnter event located in HostContainer of elementHost,for detect when mouse enter try following code:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            elementHost1.HostContainer.MouseEnter += new System.Windows.Input.MouseEventHandler(HostContainer_MouseEnter);
        }
        void HostContainer_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            MessageBox.Show("Mouse entered");
        }

    }

这篇关于Winform ElementHost 中的 MouseEnter 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆