100 lines
2.6 KiB
C#
100 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace VisualComponentsLib
|
|
{
|
|
//Поле для ввода адреса электронной почты (адрес электронной почты должен соответствовать шаблону)
|
|
public partial class MyEmailTextBox : UserControl
|
|
{
|
|
//Шаблон для textbox
|
|
private string pattern;
|
|
|
|
private string example = "example@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;
|
|
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);
|
|
}
|
|
}
|
|
}
|