MouseWheel

G

Guest

I have a form with buttons and a custom control I wrote showing a list of
items. I would like to scroll the list when the mouse is over the control
and the mouse wheel is moved but yet don't want to set the focus to my
control. How can I do this. Currently, I set the focus to my control when
the mouse hovers over my control but this could cause a user problems with
the lost focus event on any other control he is using at the time. It seems
that only the control with the focus receives the MouseWheel events. I also
tried the capture method but it doesn't capture the mousewheel events.
 
C

Carl Summers

Unless you have more than one of these custom controls (albeit very
possible) would the form's mousewheel event suffice to scroll your
control?

Carl Summers
 
R

Robby

When the mouse wheel is scrolled check that the cursor is positioned over
your control. If it is then scroll your control.

--Robby
 
G

Guest

Thanks for answers. I am writing a custom control which may be used by
different users and I was trying to handle scrolling automatically from
within my control without the need for the user to write any code outside of
the control.

I was thinking of trying to intercept all window's messages and pull out any
wheel scroll events if the mouse is over my control, if not, then pass on the
messages but not sure how to do this.
 
B

Brian Schwartz

I strongly recommend against this. You're trying to work around standard
Windows behavior. If I'm using your control on a form I'm building, and I
have other controls that also make use of the mouse wheel, I would be very
annoyed to scroll those other controls and also find your control moving.
The nice thing about the mouse wheel is that it doesn't have to be over the
control to scroll; it can be anywhere on the screen. I might happen to have
it over your control.

If easily scrolling your control is important to me--for example, if it's
the main control on the form, or something like that--then I will code and
design the form to make sure that control has focus as often as is
reasonable. IMO, you should not try to circumvent the standard behavior in
this case. If you were merely designing a form of your own--not a control
for others to use--then what you want to do might be a good idea.

Brian
 
R

Robby

Take a look at the System.Windows.Forms.Control class. The events you want
to pay particular attention to are Control.MouseEnter, Control.MouseHover,
Control.MouseLeave and Control.MouseWheel.

--Robby
 

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