469,946 Members | 1,787 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,946 developers. It's quick & easy.

MouseWheel

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
5 2506
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

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
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
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
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.

Similar topics

6 posts views Thread by deko | last post: by
reply views Thread by Mark Johnson | last post: by
1 post views Thread by Niranjan | last post: by
7 posts views Thread by Daisy | last post: by
1 post views Thread by Nicholas Shewmaker | last post: by
3 posts views Thread by Dave K | last post: by
reply views Thread by WaterWalk | last post: by
1 post views Thread by =?Utf-8?B?UmljaA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.