PIbd-31_Rodionov.I.A._COP_28/COP/RodionovLibrary/VisualComponents/TextBoxControl.cs
2024-09-05 23:36:10 +04:00

62 lines
1.8 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 RodionovLibrary.Exceptions;
using System.Text.RegularExpressions;
namespace RodionovLibrary.VisualComponents
{
public partial class TextBoxControl : UserControl
{
private string? tooltipText;
private event EventHandler? _valueChanged;
public event EventHandler ValueChanged
{
add { _valueChanged += value; }
remove { _valueChanged -= value; }
}
public string? Pattern { get; set; }
public string Value {
get
{
if (Pattern == null)
throw new NullPatternException("Не задан шаблон!");
if (!new Regex(Pattern).IsMatch(textBox.Text))
throw new NotMatchPatternException("Введенное значение не соответствует шаблону!");
return textBox.Text;
}
set
{
if (Pattern == null)
throw new NullPatternException("Не задан шаблон!");
if (!new Regex(Pattern).IsMatch(value))
throw new NotMatchPatternException("Введенное значение не соответствует шаблону!");
textBox.Text = value;
}
}
public TextBoxControl()
{
InitializeComponent();
}
public void SetTooltipText(string text)
{
tooltipText = text;
}
private void TextBox_TextChanged(object sender, EventArgs e)
{
_valueChanged?.Invoke(sender, e);
Value = textBox.Text;
}
private void TextBox_MouseEnter(object sender, EventArgs e)
{
toolTip.Show(tooltipText ?? "", textBox);
}
}
}