Mouse scroll affects both the NumericUpDown control and the containing Panel

I

illegal.prime

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
 
I

illegal.prime

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
 
I

illegal.prime

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
 
I

illegal.prime

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
 

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