Capturing mouse event at higher level in containment hierarchy


Hey all, I have fairly deep nesting of controls in my Form. At a
relatively high level in this hierarchy I would like to react to mouse
click, mouse down, mouse up events.

But the events don't seem to perculate up through the containment

Any suggestions?




So it looks like the only way to get this to work is to add a listener
to the contained control's Enter event. Apparently if you add a
Control (an object whose class extends Control) named X to a Panel,
UserControl, etc named Y. And then if you want to listen to mouse
events (movement, click, etc) on X, you need to get a reference to the
X and listen to the appropriate mouse event on X.

Hope that helps someone else out there,



Stoitcho Goutsev \(100\)


No event does not perculate. Each control has its own surface and the mouse
events are sent to the window (control) under the mouse cursor. Windows
forms doesn't support event bubbling. Upcoming WPF will support event
bubbling and event tunneling which will allow events going up and down in
the controil hierarchy.
For now what you can do is to use message filters. Windows mouse messages
comes through the message queue so they can be handled on the level of the

The following is a thread where I heve posted some sample code:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question