KOP_Library_v5/ViewComponents/Input_text.cs

82 lines
1.5 KiB
C#
Raw Normal View History

2023-10-06 02:36:27 +04:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ViewComponents.Exeption;
namespace ViewComponents
{
public partial class Input_text : UserControl
{
public Input_text()
{
InitializeComponent();
}
public event Action<string?> ItemChange;
private bool isMin = false;
private bool isMax = false;
public int? minlen;
public int? maxlen;
public string? Element
{
get
{
if (!isMax || !isMin) throw new TextBoundsNotSetExeption("Диапазон не задан");
if(textBox1.Text.Length < minlen || textBox1.Text.Length > maxlen) throw new TextOutOfBoundsExeption("Слово не из диапазона");
return textBox1.Text;
}
set
{
if (isMin && isMax && value != null && value.Length >= minlen && value.Length <= maxlen) textBox1.Text = value;
}
}
public int? MinLen
{
get
{
if (isMin == true) return minlen;
else return null;
}
set
{
if (value.HasValue)
{
minlen = value;
isMin = true;
}
}
}
public int? MaxLen
{
get
{
if (isMax == true) return maxlen;
else return null;
}
set
{
if (value.HasValue)
{
maxlen = value;
isMax = true;
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
ItemChange?.Invoke(textBox1.Text);
}
}
}