-1

In C# with .Net 4.5, disabled NumericUpDown and ComboBox controls still respond to mousewheel events. This seems like a bug.

Is this a bug in WinForms? Short of subclassing the controls, how can I prevent this from happening?

[Edit: reproduction steps] Using Visual Studio Professional 2012 Update 4 on Windows 10, I do the following:

  1. Create a new WinForms app.
  2. Open Form1 in the Designer. Drag in a Panel from the toolbox.
  3. Drag a ComboBox and a NumericUpDown into the panel.
  4. Set 3 strings "A", "B", "C" on the ComboBox using the Properties panel -> Data -> Items
  5. Drag in a checkbox and put it below the Panel. Name it "Disabled".
  6. Double click the checkbox to create an event handler:

    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        panel1.Enabled = !checkBox1.Checked;
    }
    
  7. Compile and run. Hit the checkbox so that panel1.Enabled is false, then mouse over the NumericUpDown and move the mouse wheel. The numbers change even though the NumericUpDown is drawn disabled.

damian
  • 3,604
  • 1
  • 27
  • 46
  • I can't replicate this. If the controls are disabled they can't receive focus and therefore I can't get them to respond to mouse events. Have you got some steps to replicate this or code to show? – Equalsk Jan 28 '16 at 09:10
  • In my case the controls are children of a container control that is disabled. – damian Jan 28 '16 at 09:15
  • Still can't do it. I've put them in a Panel and disabled only the panel and they still don't respond to mouse events. Can you provide the exact specifics and steps? – Equalsk Jan 28 '16 at 09:17
  • I can reproduce here. It's only scrollwheel events, not all mouse events. – damian Jan 28 '16 at 09:21
  • You being able to reproduce it is great and all but if nobody else can then nobody can help. I know it's scroll events. Unless you can provide more information then I have to defer to someone else, maybe they know something I don't. – Equalsk Jan 28 '16 at 09:24
  • To be totally clear: I create a new WinForms app, drag in a Panel from the toolbox, drag a ComboBox and a NumericUpDown into the panel, set 3 strings "A", "B", "C" on the combobox. Outside of the panel I add a checkbox. When the checkbox check changes, I set `panel1.Enabled = checkbox1.Checked`. Compile, run. Hit the checkbox a couple of times so that panel1.Enabled is false, then mouse over the numericupdown and move the mouse wheel. The numbers change even though the numericupdown is drawn disabled. – damian Jan 28 '16 at 09:24
  • OK so they way this would work is that when the checkbox is checked (true) the panel is enabled, and when it's unchecked (false) it would be disabled. So for me because the panel is set to enable by default and the checkbox is unchecked by default then on load everything is enabled and I can use those controls. If I check the box then it's true and therefore the panel still works. When I uncheck the box the panel becomes disabled and I can no longer use the controls. So I have to check the box twice before I get results. Are you sure you don't just need to disable the panel by default? – Equalsk Jan 28 '16 at 09:28
  • No, the whole point is to be able to programmatically enable/disable parts of the UI based on the model state. – damian Jan 28 '16 at 09:29
  • Sorry I edited my comment above with more details, guess that got lost in between. – damian Jan 28 '16 at 09:31
  • I've done exactly as you've said and they still don't respond to mouse events. When I said disable the panel by default I just meant setting it's initial enabled state to false so that it matches the initial state of the checkbox. Anyway I'm going to have to let someone else try because at the moment it seems to be being caused by something you're unfortunately not showing us. – Equalsk Jan 28 '16 at 09:39

1 Answers1

-1

After attempting to reproduce this on a colleague's system, we determined that the problem was caused by a third party tool that I have installed to enable scrolling the window under the mouse pointer without that window requiring focus (a la OSX).

damian
  • 3,604
  • 1
  • 27
  • 46
  • Well I feel a whole lot better now. Permission to do the "I told you so" dance? ;-) Glad you got it sorted. (FYI I didn't downvote, not sure who the ninja is) – Equalsk Jan 28 '16 at 11:21
  • Go for it :D And thanks, so am I (glad I got it sorted I mean) - very happy to hit the 'won't fix' button on our JIRA. – damian Jan 28 '16 at 11:56