本文介绍了从面板的MouseEnter和鼠标离开事件和它的子控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含子控件面板。
I have a Panel that contains child controls.
如果我处理小组的MouseEnter和鼠标离开事件,和他的孩子的MouseEnter和鼠标离开事件,这里是提高的顺序:
If i handling the Panel's MouseEnter and MouseLeave events, and his child's MouseEnter and MouseLeave events, here is the order of raising:
Panel.MouseEnter
Panel.MouseLeave
Child1.MouseEnter
Child1.MouseLeave
Panel.MouseEnter
Panel.MouseLeave
但我需要提高的顺序如下:
but i need the following order of raising:
Panel.MouseEnter
Child1.MouseEnter
Child1.MouseLeave
Panel.MouseLeave
这可能吗?
推荐答案
如果你不介意创建一个用户控件(若想面板或其他父容器派生),重写你的父母的 OnMouseLeave在
方法如下所示。
If you dont mind creating a usercontrol(derived from the panel or other parent container you wish),Override your parent's OnMouseLeave
method to look like the following..
protected override void OnMouseLeave(EventArgs e)
{
if(this.ClientRectangle.Contains(this.PointToClient(Control.MousePosition)))
return;
else
{
base.OnMouseLeave(e);
}
}
然后,事件提高将在所要求的顺序。
Then, the event raising will be in the required order.
这篇关于从面板的MouseEnter和鼠标离开事件和它的子控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!