using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WinFormsLibrary { public partial class NumberTextBox : UserControl { public int? maxValue = null; public int? minValue = null; public string errorText = ""; public NumberTextBox() { InitializeComponent(); } public int? MinValue { get { return minValue; } set { if (value == null) return; minValue = value; numericUpDown.Minimum = (int)value; } } public int? MaxValue { get { return maxValue; } set { if (value == null) return; maxValue = value; numericUpDown.Maximum = (int)value; } } public decimal? Value { get { if (CheckRanges(numericUpDown.Value)) { return numericUpDown.Value; } else { return null; } } set { if (CheckRanges(value)) { numericUpDown.Value = (decimal)value; } } } private bool CheckRanges(decimal? value) { if (MinValue == null || MaxValue == null) { errorText = "Ошибка, диапазоны не заданы."; return false; } if (value < MinValue || value > MaxValue) { errorText = "Ошибка, значение не входит в заданный диапазон."; return false; } errorText = "Ошибок нет."; return true; } public event EventHandler DateChanged { add { numericUpDown.ValueChanged += value; } remove { numericUpDown.ValueChanged -= value; } } } }