5

I have been trying to find a way to disable the scrolling of a NumericUpDown when I accidentally mouse-over a NumericUpDown. Is there a way to do this using the properties?

I found a way to disable it using code for a combobox, but not directly within the Properties panel in the Designer view.

This was the code I found:

    void comboBox1_MouseWheel(object sender, MouseEventArgs e) {
        ((HandledMouseEventArgs)e).Handled = true;
    }

I found the code from this link:

C# - how do I prevent mousewheel-scrolling in my combobox?

I have a lot of these NumericUpDowns in my Design, and would therefore like to have a way to just disable the mouse scrolling when I accidentily mouse-over the NumericUpDown. So if there is a way to do this directly in the Properties, it would help a lot. Thanks in advance!

Broots Waymb
  • 4,713
  • 3
  • 28
  • 51
Beneagle
  • 93
  • 8
  • I'm not sure about the properties, but you could always create your own control that disables the mouse wheel, then replace all of the NumericUpDowns with your custom one. Not sure if that's the best option though. – Broots Waymb Jan 22 '20 at 15:10

2 Answers2

8

You cannot set this in designer properties. But you can use a little cheat code to do this:

private void Form1_Load(object sender, EventArgs e)
{
    foreach (Control ctl in Controls)
    {
        if (ctl.GetType() == typeof(NumericUpDown))
            ctl.MouseWheel += Ctl_MouseWheel;
    }
}

private void Ctl_MouseWheel(object sender, MouseEventArgs e)
{
    ((HandledMouseEventArgs) e).Handled = true;
}

I just tested this and it did the job nicely.

LocEngineer
  • 2,847
  • 1
  • 16
  • 28
2

If you do not need the Up and Down buttons to do anything, then you can set the Increment property to 0

FonnParr
  • 325
  • 1
  • 7