Skip to content

How to signal WinForm control input out of range?

Bob Lewiston

Asked Mar 5, 2009, 10:07 AM EST1 answer
Share
LinkedInX

Is there a way (perhaps via EventArgs) to signal the app when a user tries to enter out-of-range input into a WinForm control? (Specifically, a number in a NumericUpDown control numericUpDown1 that is larger than numericUpDown1.Maximum?) Yes, I know the control won't allow the input, but I want to display an error message if this happens.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0
    You can derive a customized exeption and invoke it

    public class NumericUpDownException : ApplicationException
        {
            public NumericUpDownException() { }
            public NumericUpDownException(string message)
                : base("Index out of range exception")
            { }
            public void Trigger(NumericUpDown control)
            {
                if (control.Maximum < control.Value)
                {
                    throw this;
                }
            }
        }
    0