ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

NumericUpDown SafeValue()

http://peshir.blogspot.nl/2011/02/safely-set-numericupdown-control-value.html

Source

public static void SafeValue(this NumericUpDown c, decimal value)
{
   c.Value = Math.Max(c.Minimum, Math.Min(value, c.Maximum));
}

Example

Use control.SafeValue(42) instead of control.Value = 42.

Author: peSHIr

Submitted on: 6 mei 2014

Language: C#

Type: System.Windows.Forms.NumericUpDown

Views: 4208