Search code examples
c#winformscomboboxmousewheelnumericupdown

Prevent mousewheel on controls with Enabled = false


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.


Solution

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