PIbd-32_Turner_I.A._COP_10/COP/VisualCompLib/MyEmailTextBox.cs

94 lines
1.7 KiB
C#
Raw Permalink Normal View History

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
{
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;
}
}
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-16 11:05:11 +04:00
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);
}
2023-09-16 11:05:11 +04:00
private EventHandler onValueChanged;
public event EventHandler ValueChanged
{
2023-09-16 11:05:11 +04:00
add
{
2023-09-16 11:05:11 +04:00
onValueChanged += value;
}
2023-09-16 11:05:11 +04:00
remove
{
2023-09-16 11:05:11 +04:00
onValueChanged -= value;
}
}
2023-09-16 11:05:11 +04:00
private void textBox_TextChanged(object sender, EventArgs e)
{
onValueChanged?.Invoke(sender, e);
}
}
}