using System; using ToolTip = System.Windows.Forms.ToolTip; using System.Text.RegularExpressions; using System.Windows.Forms; using System.Drawing; namespace VisualComponentsLib { public partial class MyEmailTextBox : UserControl { //Шаблон для textbox private string pattern; //Пример ввода private string example = "ti@gmail.com"; public MyEmailTextBox() { InitializeComponent(); } public string Pattern { get { return pattern; } set { pattern = value; } } public string TextBoxValue { get { Regex rg = new Regex(Pattern); bool address = rg.IsMatch(emailTextBox.Text); if (address) { return emailTextBox.Text; } else { Error = "Некорректный ввод"; return null; } } set { Regex rg = new Regex(Pattern); bool address = rg.IsMatch(value); if (address) { emailTextBox.Text = value; } else { Error = "Некорректный ввод"; } } } public string Error { get; private set; } public void setExample(string str) { Regex rg = new Regex(Pattern); bool address = rg.IsMatch(str); if (address) { example = str; } } private void textBox_Enter(object sender, EventArgs e) { int VisibleTime = 2000; //ms ToolTip tooltip = new ToolTip(); tooltip.Show(example, emailTextBox, 30, -20, VisibleTime); } private EventHandler onValueChanged; public event EventHandler ValueChanged { add { onValueChanged += value; } remove { onValueChanged -= value; } } private void textBox_TextChanged(object sender, EventArgs e) { onValueChanged?.Invoke(sender, e); } } }