letting child control handler mousewheel event

G

Guest

hi,

I've got a custom control which I've overriden the OnMouseWheel event and
made it scroll. Simple enough.

This control has a series of child controls which I'd like it to pass on the
MouseWheel events to if the mouse if over the control (assuming i need to do
a hit test?) (at the moment, the child control needs to be clicked on to
assume focus before it received the mouse wheel events)

Anyway, I just wondered how the easiest way of doing this is? is there
something easy that does this? any references anyone knows about that i
could read?

TIA
Sam
 
S

Stoitcho Goutsev \(100\)

sammartin,

Despite that the mouse wheel is part of the mouse device it events are
handled differently by windows - simialar to the keyboard events. That is
the control having the focus receives the mouse wheel. This is how Windows
OS dispatches the messages. The default winproc implementation will forward
the message down to the control parent if the message is not handled. I
haven't tried it, but I suspect that Windows Forms won't do that. It will
probably fire the event on the level of the focused control and won't
propagate it down. Anyways this is not what you need. As as understand you
need to event to go in the oposite direction - form the parent to the child.
The onlyway that I can see is to focus that child when the mouse enters the
control. This may not be good for the user experience. Imagine the text
boxes get the focus anytime the user move the mouse around.

However to hittest the control under the mouse cursor you can use
Control.GetChildAtPoint method.
 
S

Stoitcho Goutsev \(100\)

I glanced thrugh the solution and what I first saw is tha the focus changed
as the mouse moves. I can see this causing usability problems.
 
S

Stoitcho Goutsev \(100\)

As I said I didn't read throught the article I just saw the first code
snippet which is exactly this. Maybe this was an example how it shouldn't be
done :)

Anyways I'm glad you found solution to your problem.
 
G

Guest

yeah, was exactly that. the solution, is tidy and works well. just wanted
anyone else face with same problem not to be put off.

all good.

sam
 

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

Top