Glitch with Maximum value of NumericUpDown C# Visual Studio

Viewed 38

I have set the NumericUpDowns Maximum Values to 100 (design part) but if the user presses a number that is longer than 3 digits (for example 5555) it shows up as 5100. Should I set the maximum value to an event or is there another way I can limit the user entering 4 digits numbers? Fourth NumericUpDown

1 Answers

You just need to add the following code to the keyup event:

private void numericUpDown1_KeyUp(object sender, KeyEventArgs e)
{
    decimal tmp = Convert.ToDecimal(numericUpDown1.Value.ToString());
    if (tmp >= 100)
    {
        numericUpDown1.Value = 100;
    }
}

After we set the maximum value under normal circumstances, it will only judge after enter or lose focus.

When you add it to the keydown event. It will become 5100.

enter image description here

Related