58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using Library14Petrushin.Exeptions;
|
|
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 Library14Petrushin
|
|
{
|
|
public partial class RangeTextBox : UserControl
|
|
{
|
|
public int MinLength { get; set; }
|
|
public int MaxLength { get; set; }
|
|
|
|
public event EventHandler? ValueChanged;
|
|
|
|
public string InputValue
|
|
{
|
|
get
|
|
{
|
|
if (MinLength == 0 && MaxLength == 0)
|
|
{
|
|
throw new RangeException("Диапазон не задан.");
|
|
}
|
|
if (textBox1.Text.Length < MinLength || textBox1.Text.Length > MaxLength)
|
|
{
|
|
throw new RangeException("Введенное значение не входит в диапазон.");
|
|
}
|
|
return textBox1.Text;
|
|
}
|
|
set
|
|
{
|
|
if (MinLength != 0 && MaxLength != 0)
|
|
{
|
|
if (value.Length >= MinLength && value.Length <= MaxLength)
|
|
{
|
|
textBox1.Text = value;
|
|
ValueChanged?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new RangeException("Диапазон не задан.");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void TextBox1_TextChanged(object sender, EventArgs e)
|
|
{
|
|
ValueChanged?.Invoke(this, e);
|
|
}
|
|
}
|
|
}
|