2024-09-05 21:45:49 +04:00
|
|
|
|
using Controls.Exceptions;
|
|
|
|
|
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 Controls
|
|
|
|
|
{
|
2024-09-05 23:08:08 +04:00
|
|
|
|
public partial class CustomTextBoxNumber : UserControl
|
2024-09-05 21:45:49 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
2024-09-05 23:08:08 +04:00
|
|
|
|
public CustomTextBoxNumber()
|
2024-09-05 21:45:49 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Шаблон вводимого значения
|
|
|
|
|
/// </summary>
|
2024-09-05 23:08:08 +04:00
|
|
|
|
private string? _numberPattern;
|
|
|
|
|
|
2024-09-06 00:43:56 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Шаблон вводимого значения
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string? NumPattern
|
2024-09-05 23:08:08 +04:00
|
|
|
|
{
|
|
|
|
|
get { return _numberPattern; }
|
|
|
|
|
set { _numberPattern = value; }
|
|
|
|
|
}
|
2024-09-05 21:45:49 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Введенное значение
|
|
|
|
|
/// </summary>
|
2024-09-05 21:53:15 +04:00
|
|
|
|
public string? TextBoxNumber
|
2024-09-05 21:45:49 +04:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (NumPattern == null)
|
|
|
|
|
{
|
|
|
|
|
throw new CustomNumberException("Шаблон не заполнен!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Regex regex = new Regex(NumPattern);
|
|
|
|
|
if (regex.IsMatch(textBoxNumber.Text))
|
|
|
|
|
{
|
|
|
|
|
return textBoxNumber.Text;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new CustomNumberException(textBoxNumber.Text + " не соответствует шаблону!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Regex regex = new Regex(NumPattern!);
|
|
|
|
|
if (regex.IsMatch(value))
|
|
|
|
|
{
|
|
|
|
|
textBoxNumber.Text = value;
|
|
|
|
|
}
|
2024-09-06 10:49:14 +04:00
|
|
|
|
|
2024-09-05 21:45:49 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Событие, вызываемое при смене значения
|
|
|
|
|
/// </summary>
|
|
|
|
|
private EventHandler _onValueChangedEvent;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Событие, вызываемое при смене значения
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event EventHandler ValueChanged
|
|
|
|
|
{
|
|
|
|
|
add
|
|
|
|
|
{
|
|
|
|
|
_onValueChangedEvent += value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remove
|
|
|
|
|
{
|
|
|
|
|
_onValueChangedEvent -= value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Смена значения
|
|
|
|
|
/// </summary>
|
2024-09-05 21:53:15 +04:00
|
|
|
|
private void CustomNumberBox_NumberChanged(object sender, EventArgs e)
|
2024-09-05 21:45:49 +04:00
|
|
|
|
{
|
|
|
|
|
_onValueChangedEvent?.Invoke(sender, e);
|
|
|
|
|
}
|
2024-09-06 00:43:56 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-09-06 10:38:12 +04:00
|
|
|
|
/// Выведение подсказки на экран
|
2024-09-06 00:43:56 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private void textBox_Enter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
int visibleTime = 2000;
|
|
|
|
|
ToolTip tooltip = new ToolTip();
|
2024-11-05 22:04:24 +04:00
|
|
|
|
tooltip.Show("(ХХХХ)ХХ-ХХ-ХХ", textBoxNumber, 30, -20, visibleTime);
|
2024-09-06 00:43:56 +04:00
|
|
|
|
}
|
2024-09-05 21:45:49 +04:00
|
|
|
|
}
|
|
|
|
|
}
|