How to make NumericUpDown return to the minimum value when the UpButton is clicked and the current value is the maximum?

1

I'm using NumericUpDown in an application where the user can set a desired time for any action to be taken. There are three NumericUpDown : one for the hour (from 0 to 23 ), another for minute ( 0 a 59 in>) and another for second ( 0 to 59 ).

The problem is that when the user increments the values by means of the NumericUpDown increment button when the current value is the maximum configured value ( 23 for hours and 59 for minutes and seconds), of course the value is not incremented further. However, I would like to know if there is any way to get the values back to the minimum in this situation (ie for 0 ).

    
asked by anonymous 02.09.2016 / 15:04

1 answer

1

One way to solve would be to compare the current value with the minimum and maximum value allowed.

When the value reaches the minimum, change the value to the maximum and when it reaches the maximum, change the value to the minimum.

In event Click of NumericUpDown do:

private void numericUpDown2_Click(object sender, EventArgs e)
{
    decimal valor = numericUpDown2.Value;

    if (valor.Equals(numericUpDown2.Minimum)) {
        numericUpDown2.Value = numericUpDown2.Maximum;
    } 

    if (valor.Equals(numericUpDown2.Maximum)) {
        numericUpDown2.Value = numericUpDown2.Minimum;
    }  
}
    
02.09.2016 / 15:56