3

When the user enters a value above numericUpDown.Maximum, the control's value is automatically set to the maximum. I'd like to display a MessageBox when this occurs, but I'm not able to do that because control.Value and control.Text already contain the automatically set value, maximum, when Validating event is raised.

private void numericUpDown_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
       NumericUpDown control = sender as NumericUpDown;
       decimal newValue = control.Value;

       // decimal newValue;
       // decimal.TryParse(control.Text, out newValue)

       if (newValue > control.Maximum || newValue < control.Minimum)
       {
            // MessageBox

        }

}

Thanks

alhazen
  • 1,907
  • 3
  • 22
  • 43

1 Answers1

3

Nagging the user by slapping her with message boxes doesn't make for the greatest user interface. But you can easily do it just by setting the min and max smaller/larger and checking the value in the ValueChanged event.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Are you suggesting that the value is changed without notification? I agree that message boxes can be annoying. But using ASP.NET like validation controls can be both more informative and less annoying. – atoMerz Apr 02 '14 at 17:15
  • No. This question doesn't have anything to do with asp.net – Hans Passant Apr 02 '14 at 17:18
  • "ASP.NET like" validation controls, I mean the method used there not the controls themselves. Implementation is possible and has been discussed in the link in my comment on the question. – atoMerz Apr 02 '14 at 17:28