2023-09-15 21:10:27 +04:00
|
|
|
|
using System;
|
|
|
|
|
using ToolTip = System.Windows.Forms.ToolTip;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
2023-09-28 20:53:57 +04:00
|
|
|
|
namespace VisualCompLib
|
2023-09-15 21:10:27 +04:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
2023-09-16 11:05:11 +04:00
|
|
|
|
Error = "Некорректный ввод";
|
|
|
|
|
return null;
|
2023-09-15 21:10:27 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Regex rg = new Regex(Pattern);
|
|
|
|
|
bool address = rg.IsMatch(value);
|
|
|
|
|
if (address)
|
|
|
|
|
{
|
|
|
|
|
emailTextBox.Text = value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-09-16 11:05:11 +04:00
|
|
|
|
Error = "Некорректный ввод";
|
2023-09-15 21:10:27 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-16 11:05:11 +04:00
|
|
|
|
public string Error
|
|
|
|
|
{
|
|
|
|
|
get; private set;
|
|
|
|
|
}
|
2023-09-15 21:10:27 +04:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-16 11:05:11 +04:00
|
|
|
|
private EventHandler onValueChanged;
|
|
|
|
|
public event EventHandler ValueChanged
|
2023-09-15 21:10:27 +04:00
|
|
|
|
{
|
2023-09-16 11:05:11 +04:00
|
|
|
|
add
|
2023-09-15 21:10:27 +04:00
|
|
|
|
{
|
2023-09-16 11:05:11 +04:00
|
|
|
|
onValueChanged += value;
|
2023-09-15 21:10:27 +04:00
|
|
|
|
}
|
2023-09-16 11:05:11 +04:00
|
|
|
|
remove
|
2023-09-15 21:10:27 +04:00
|
|
|
|
{
|
2023-09-16 11:05:11 +04:00
|
|
|
|
onValueChanged -= value;
|
2023-09-15 21:10:27 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-16 11:05:11 +04:00
|
|
|
|
|
|
|
|
|
private void textBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
onValueChanged?.Invoke(sender, e);
|
|
|
|
|
}
|
2023-09-15 21:10:27 +04:00
|
|
|
|
}
|
|
|
|
|
}
|