using ComponentLibrary1.limited_text; 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 ComponentLibrary1 { public partial class LimitedText : UserControl { private event EventHandler? _changeEvent; public event EventHandler ChangeEvent { add { _changeEvent += value; } remove { _changeEvent -= value; } } private int? _min = null; public int? Min { get { return _min; } set { if (value < 0) { return; } if (Max != null && value > Max) { return; } _min = value; } } private int? _max = null; public int? Max { get { return _max; } set { if (value < 0) { return; } if (Max != null && value < Min) { return; } _max = value; } } public string TextField { get { if (Min == null || Max == null) { throw new RangeUndefinedException(); } if (textBox.Text.Length < Min || textBox.Text.Length > Max) { throw new OutOfRangeException((int)Min, (int)Max); } return textBox.Text; } set { if (Min == null || Max == null) { return; } if (value.Length >= Min && value.Length <= Max) { return; } } } public LimitedText() { InitializeComponent(); } private void textBox_TextChanged(object sender, EventArgs e) { _changeEvent?.Invoke(this, e); } } }