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

Mouse scroll affects both the NumericUpDown control and the containing Panel

P: n/a
Hey all, I have a NumericUpDown control on a Panel or potentially a
Form that have AutoScroll enabled.

When the NumericUpDown is active I would like the Form/Panel/whatever
not to scroll when I scroll the value in the NumericUpDown.

I can add an additional handler to the MouseWheel event on the
NumericUpDown, but how do I stop the Form/Panel/Whatever from scrolling
when the value is changing in the NumericUpDown?

Thanks,
Novice

Apr 20 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
So I have found a solution but it is far from ideal. Basically, I
override the Form/Panel/Whatever's OnMouseWheel and OnClick methods,
when the user clicks on the Form/Panel/Whatever I set a member variable
(I can't use the Focus method for reasons I'll detail below) called
UserFocus to true. Then in the OnMouseWheel override, I check to
ensure that the UserFocus is true before I invoke the
base.OnMouseWheel.

There are several problems:
1. There doesn't appear to be a way to set the Focus to the
Panel/Form/Whatever instead of the NumericUpDown - if I try to invoke
either Focus or Activate in the OnClick method, the property Focus is
still false in the OnMouseWheel method.
2. Now I also have to override some method in the NumericUpDown so that
I can reset the Panel/Form/Whatever's UserFocus member to false.

Any suggestions on:
a) How to remove focus from the currently selected control if the user
clicks in a "blank" portion of the Panel/Form/Whatever?

or even better - what the proper way is to solve this problem

Thanks,
Novice

Apr 20 '06 #2

P: n/a
Okay... now I'm sure that someone could argue this point, but it seems
to me that this is a bug.

If I put my NumericUpDown in a panel, then invoke the Panel's Focus
method, then in the OnMouseWheel method I test the Panel's Focused
property, the property IS properly set to focused!!!

But the exact same logic as above fails if I try to set the Form to
focused.

Anyway, I'll fix up the code and post it if anyone is interested - let
me know.

Novice

Apr 20 '06 #3

P: n/a
sb
Please post a short example...I'm unclear on what the problem is.

-sb
<il***********@gmail.com> wrote in message
news:11*********************@t31g2000cwb.googlegro ups.com...
Okay... now I'm sure that someone could argue this point, but it seems
to me that this is a bug.

If I put my NumericUpDown in a panel, then invoke the Panel's Focus
method, then in the OnMouseWheel method I test the Panel's Focused
property, the property IS properly set to focused!!!

But the exact same logic as above fails if I try to set the Form to
focused.

Anyway, I'll fix up the code and post it if anyone is interested - let
me know.

Novice

Apr 20 '06 #4

P: n/a
So apparently the crux of the problem is that there are certain classes
that extend Control (such as Form and UserControl) that when you invoke
their Focus method, they will transfer focus to their children unless
you either set all the children's TabStop property to False or set the
Form or UserControl's ActiveControl to null.

Anyway, my work-around (instead of doing either of the above two
options) was just to use a Panel instead of either a Form or a
UserControl.

So apparently this is expected behaviour... but I have to think that
many developers have been and will be bitten by this one

Novice

Apr 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.