75 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}
}
}