MouseWheel Events

B

bern11

I have an panel containing an image which creates scrollbars if the
image is too large for the panel. MouseWheel events automatically
scroll the scroll-bars. How do I intercept the mouse-wheel and make it
perform another function? I added a delegate mousewheel handler, but
now I get both events (panel scroll plus intended new function). I want
to switch between functions based on a flag.

I've already sub-classed the panel to gain access to other properties,
should I simply over-ride the mousewheel event and call the base event
based on a flag setting? Seems kindof the hard way....

PS. I also just noticed I never set the autoscroll property to true,
but the autoscrollbar behaviour seems to be enabled when I set the
autoscrollminsize property. Is this supposed to happen or did I just
get lucky and my code might not always work.

PPS. Why doesn't MouseWheel event show up in the designer? I had to
type the whole thing in, delegate declaration and all.
 
O

Oliver Sturm

Hello bern11,
I've already sub-classed the panel to gain access to other properties,
should I simply over-ride the mousewheel event and call the base event
based on a flag setting? Seems kindof the hard way....

Well, this seems kind of the right way to me though :) Hard way? Well,
you're doing something non-standard, so you first have to find a way to
get rid of the standard behaviour, and stealing away the event is often a
good way of doing that.
PS. I also just noticed I never set the autoscroll property to true, but
the autoscrollbar behaviour seems to be enabled when I set the
autoscrollminsize property. Is this supposed to happen or did I just get
lucky and my code might not always work.

Have a look at Reflector - it shows you that the setter for the
AutoScrollMinSize property looks like this:

set
{
if (value != this.userAutoScrollMinSize)
{
this.userAutoScrollMinSize = value;
this.AutoScroll = true;
base.PerformLayout();
}
}

So, it definitely looks like the programmer wanted AutoScroll to be set to
true in this case.
PPS. Why doesn't MouseWheel event show up in the designer? I had to type
the whole thing in, delegate declaration and all.

Because it's marked [Browsable(false)] on the Control (once more, see
Reflector). Oh, why did they do that? I don't know. Maybe it's a mistake,
or they had a genuine reason not to expose the event - I couldn't find
much useful info about this.


Oliver Sturm
 

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