PIbd-32_Ismailov_R.I._COP_19/WinForms/VisualComponentsLib/MyEmailTextBox.cs

100 lines
2.6 KiB
C#
Raw Normal View History

2023-09-20 22:19:14 +04:00
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;
2023-09-20 23:39:14 +04:00
namespace VisualComponentsLib
2023-09-20 22:19:14 +04:00
{
2023-09-21 10:11:33 +04:00
//Поле для ввода адреса электронной почты (адрес электронной почты должен соответствовать шаблону)
2023-09-20 22:19:14 +04:00
public partial class MyEmailTextBox : UserControl
{
//Шаблон для textbox
private string pattern;
2023-09-21 10:11:33 +04:00
private string example = "example@gmail.com";
2023-09-20 22:19:14 +04:00
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)
{
2023-09-21 10:11:33 +04:00
int VisibleTime = 2000;
2023-09-20 22:19:14 +04:00
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);
}
}
}