如何捕获子控件下方鼠标移动事件 [英] How to capture mousemove events beneath child controls

查看:195
本文介绍了如何捕获子控件下方鼠标移动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在特定表单上处理鼠标事件,如果鼠标光标位于一组坐标之间,则应触发。 -

i am trying to handle a mouseclick event on a particular form that should fire if the mouse cursor falls between a set of coordinates - lets say a square.

明白,如果我有一个空的形式,我可以简单地绑定到mousemove事件和关闭我去。但在现实中,可能有多达10个不同的重叠控件,在我的测试应用程序中,mousemove事件只有在光标位于实际表单本身时才会触发,而不是如果它超过子控件。

I understand that if i had an empty form i could simply tie in to the mousemove event and off i go. But in reality there may be up to 10 different overlapping controls and in my test app the mousemove event only fires if the cursor is on the actual form itself and not if its over a child control.

有没有人知道如何处理这个事件,当设计时有未知数量的子控件?

Does anyone know how to handle this event when there are an unknown number of child controls at design time?

有一个容易的一线使用?

Is there an easy one-liner i can use?

推荐答案

imho这里有一点二进制的情况:没有one-liner我可以看到的唯一的解决方案是获取您的控件,不实现事件到一个.NET容器。

imho there is a bit of a binary situation here : and there is no "one-liner." the only solution I can see is to get your controls that don't implement events into a .NET container that does.

当任何控件获得点击,正常预期行为是它将成为表单的活动控件(它总是可以通过this.ActivceControl访问)。

When any control gets a click, the normal expected behavior is that it will become the Active Control of the Form (which can always be accessed by this.ActivceControl).

但是,特别是如果你点击的控件捕获鼠标,一些事情必须引发一个事件,因为.NET不实现事件冒泡(如WPF)。

But, particulary if the control you clicked captures the mouse, something has got to raise an event since .NET does not implement event "bubbling" (as WPF does).

通常的方式来处理任何对象的扩展行为这是密封或任何是写一个扩展方法,我发现为控件写扩展很容易,但我不知道如果这将帮助你在这种情况下。不幸的是,我现在离开我的祖国,并没有Visual Studio来玩。

The usual way to deal with extending behavior of any object that is sealed or whatever is to write an extension method, and I have found writing extensions for Control quite easy, but I don't know if that will help you in this case. Unfortunately I am out of my home country right now, and do not have Visual Studio to play around with.

一个策略,你可以用来确定一个给定的点形式落在任何控件的边界内是枚举窗体上所有控件的区域(边界)通过'forall of Forms Control.Collection(this.Controls)。但是,如果您有重叠的控件,那么您可能会遇到多个控件可能包含给定点的问题。

One strategy you can use to determine if a given Point on a Form falls within the bounds of any Control is to enumerate the areas (Bounds) of all controls on the Form via 'forall of the Forms Control.Collection (this.Controls). But, if you have overlapping Controls, you then have the issue of more than one control possibly containing a given point.

最好,Bill

这篇关于如何捕获子控件下方鼠标移动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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