75 lines
1.9 KiB
C#
75 lines
1.9 KiB
C#
using System.Text.RegularExpressions;
|
||
|
||
namespace UserComponentsOption19
|
||
{
|
||
public partial class WriteComponent : UserControl
|
||
{
|
||
|
||
private Regex? regex;
|
||
|
||
private ToolTip toolTipTemplate = new ToolTip();
|
||
|
||
public event EventHandler? ChangeText;
|
||
|
||
public WriteComponent()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
public Regex? Template
|
||
{
|
||
get => regex;
|
||
|
||
set
|
||
{
|
||
regex = value;
|
||
}
|
||
}
|
||
|
||
public void SetTextTooltip(string toolTip)
|
||
{
|
||
toolTipTemplate.SetToolTip(textBox, toolTip);
|
||
}
|
||
|
||
private void textBox_TextChanged(object sender, EventArgs e)
|
||
{
|
||
ChangeText?.Invoke(this, e);
|
||
}
|
||
|
||
public string WriteTextInTextBox
|
||
{
|
||
get
|
||
{
|
||
if (Template == null)
|
||
{
|
||
throw new NoTemplateException("Не установлен шаблон");
|
||
|
||
}
|
||
if (!Template.IsMatch(textBox.Text))
|
||
{
|
||
throw new InvalidInputException("Введенное значение не соответствует шаблону");
|
||
}
|
||
return textBox.Text;
|
||
}
|
||
set
|
||
{
|
||
if (Template != null)
|
||
{
|
||
if (Template.IsMatch(value))
|
||
{
|
||
textBox.Text = value;
|
||
}
|
||
else
|
||
{
|
||
throw new InvalidInputException("Введенное значение не соответствует шаблону");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
textBox.Text = string.Empty;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|