6

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!

1
  • 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. Commented Jan 22, 2020 at 15:10

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

1 Comment

No this will also prevent change of the value when using arrows

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.