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

99 lines
2.5 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
{
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);
}
}
}