By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,816 Members | 2,053 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,816 IT Pros & Developers. It's quick & easy.

MouseWheel

P: n/a
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.

--
Dennis in Houston
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

Nov 21 '05 #2

P: n/a

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

--Robby
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
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.

--
Dennis in Houston

Nov 21 '05 #3

P: n/a
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.

"Robby" wrote:

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

--Robby
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
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.

--
Dennis in Houston


Nov 21 '05 #4

P: n/a
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
--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Building better tools for developers - Be part of it!
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
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.

"Robby" wrote:

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

--Robby
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
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.

--
Dennis in Houston


Nov 21 '05 #5

P: n/a
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

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
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.

"Robby" wrote:

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

--Robby
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
>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.
>
> --
> Dennis in Houston


Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.