MouseEnter event in Winform ElementHost

自作多情 提交于 2019-12-24 19:19:51

问题


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.

This are all the events I have:

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


回答1:


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");
        }

    }


来源:https://stackoverflow.com/questions/15177486/mouseenter-event-in-winform-elementhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!