78 lines
2.1 KiB
C#
78 lines
2.1 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 BulatovaComponents.Components
|
|||
|
{
|
|||
|
public partial class MailControl : UserControl
|
|||
|
{
|
|||
|
public MailControl()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
public Regex? validateEmailRegex
|
|||
|
{
|
|||
|
get;
|
|||
|
set;
|
|||
|
}
|
|||
|
|
|||
|
public event Action<string> TextChange;
|
|||
|
private string? tooltipText;
|
|||
|
public string errorMessage = "";
|
|||
|
|
|||
|
|
|||
|
public string? Email
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
//не забыл ли пользователь ввести регулярку и соответствует ли она
|
|||
|
if (validateEmailRegex == null)
|
|||
|
{
|
|||
|
errorMessage = "Пустой шаблон!";
|
|||
|
return null;
|
|||
|
}
|
|||
|
else if (!validateEmailRegex.IsMatch(textBoxMail.Text))
|
|||
|
{
|
|||
|
errorMessage = "Некорректный адрес эл. почты!";
|
|||
|
return null;
|
|||
|
}
|
|||
|
else return textBoxMail.Text;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
if (validateEmailRegex == null) errorMessage = "Пустой шаблон!";
|
|||
|
else if (!validateEmailRegex.IsMatch(value)) errorMessage = "Некорректный адрес эл. почты!";
|
|||
|
else
|
|||
|
{
|
|||
|
textBoxMail.Text = value;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void textBoxMail_TextChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
TextChange?.Invoke(textBoxMail.Text);
|
|||
|
Email = textBoxMail.Text;
|
|||
|
}
|
|||
|
|
|||
|
public void setTooltipText(string text)
|
|||
|
{
|
|||
|
tooltipText = text;
|
|||
|
}
|
|||
|
|
|||
|
private void textBoxMail_MouseEnter(object sender, EventArgs e)
|
|||
|
{
|
|||
|
toolTipEmail.Show(tooltipText ?? "", textBoxMail);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|