87 lines
2.1 KiB
C#
87 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 WinForm
|
|||
|
{
|
|||
|
public partial class NumberTextBox : UserControl
|
|||
|
{
|
|||
|
//Шаблон для textbox
|
|||
|
private string? pattern;
|
|||
|
private string example = "+7XXXXXXXXXX";
|
|||
|
|
|||
|
public NumberTextBox()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
//Публичное свойство для получения и заполнения шаблона
|
|||
|
public string? Pattern
|
|||
|
{
|
|||
|
get { return pattern; }
|
|||
|
set { pattern = value; }
|
|||
|
}
|
|||
|
|
|||
|
public string? TextBoxValue
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (new Regex(Pattern).IsMatch(textBox.Text))
|
|||
|
{
|
|||
|
return textBox.Text;
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
if (new Regex(Pattern).IsMatch(value))
|
|||
|
{
|
|||
|
textBox.Text = value;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//Метод для заполнения примера
|
|||
|
public void SetExample(string str)
|
|||
|
{
|
|||
|
if (new Regex(Pattern).IsMatch(str))
|
|||
|
{
|
|||
|
example = str;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void TextBox_Enter(object sender, EventArgs e)
|
|||
|
{
|
|||
|
int VisibleTime = 3000;
|
|||
|
ToolTip tt = new ToolTip();
|
|||
|
tt.Show(example, textBox, 0, 25, VisibleTime);
|
|||
|
}
|
|||
|
|
|||
|
private EventHandler _explicitEvent;
|
|||
|
public event EventHandler ExplicitEvent
|
|||
|
{
|
|||
|
add
|
|||
|
{
|
|||
|
_explicitEvent += value;
|
|||
|
}
|
|||
|
remove
|
|||
|
{
|
|||
|
_explicitEvent -= value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void TextBox_TextChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
_explicitEvent?.Invoke(sender, e);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|