2023-09-13 11:57:01 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2023-09-26 21:38:38 +04:00
|
|
|
|
using System.Text.RegularExpressions;
|
2023-09-13 11:57:01 +04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2023-09-26 20:44:05 +04:00
|
|
|
|
using VisualComponentsLib.CustomException;
|
2023-09-13 11:57:01 +04:00
|
|
|
|
|
|
|
|
|
namespace VisualComponentsLib
|
|
|
|
|
{
|
2023-09-13 13:48:16 +04:00
|
|
|
|
public partial class MyTextBox : UserControl
|
2023-09-13 11:57:01 +04:00
|
|
|
|
{
|
2023-09-26 21:38:38 +04:00
|
|
|
|
public string? TextBoxValue
|
2023-09-13 12:53:53 +04:00
|
|
|
|
{
|
2023-09-26 20:44:05 +04:00
|
|
|
|
get
|
|
|
|
|
{
|
2023-09-26 21:38:38 +04:00
|
|
|
|
if (checkBox.Checked)
|
2023-09-26 20:44:05 +04:00
|
|
|
|
{
|
2023-09-26 21:38:38 +04:00
|
|
|
|
return null;
|
2023-09-26 20:44:05 +04:00
|
|
|
|
}
|
2023-09-26 21:38:38 +04:00
|
|
|
|
|
|
|
|
|
if (textBox.Text.Length <= 2)
|
|
|
|
|
{
|
|
|
|
|
throw new TextBoxException("Число не введено");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (textBox.Text.Contains('.') && textBox.Text.IndexOf('.') != textBox.Text.Length - 1)
|
2023-09-26 20:44:05 +04:00
|
|
|
|
{
|
2023-09-26 21:38:38 +04:00
|
|
|
|
return textBox.Text;
|
2023-09-26 20:44:05 +04:00
|
|
|
|
}
|
2023-09-26 21:38:38 +04:00
|
|
|
|
|
|
|
|
|
throw new TextBoxException("Некорретный формат числа");
|
2023-09-26 20:44:05 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2023-09-26 21:38:38 +04:00
|
|
|
|
if (!checkBox.Checked && value == null)
|
2023-09-26 20:44:05 +04:00
|
|
|
|
{
|
2023-09-26 21:38:38 +04:00
|
|
|
|
throw new TextBoxException("Недопустимое значение null");
|
2023-09-26 20:44:05 +04:00
|
|
|
|
}
|
2023-09-26 21:38:38 +04:00
|
|
|
|
|
|
|
|
|
textBox.Text = value;
|
2023-09-26 20:44:05 +04:00
|
|
|
|
}
|
2023-09-13 12:53:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 21:38:38 +04:00
|
|
|
|
public MyTextBox()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 20:44:05 +04:00
|
|
|
|
private EventHandler _textChanged;
|
|
|
|
|
|
2023-09-13 12:53:53 +04:00
|
|
|
|
public new event EventHandler? TextChanged
|
|
|
|
|
{
|
2023-09-26 20:44:05 +04:00
|
|
|
|
add => _textChanged += value;
|
|
|
|
|
remove => _textChanged -= value;
|
2023-09-13 12:53:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 21:38:38 +04:00
|
|
|
|
private void CheckBox_CheckedChanged_1(object sender, EventArgs e)
|
2023-09-13 12:53:53 +04:00
|
|
|
|
{
|
2023-09-26 20:44:05 +04:00
|
|
|
|
if (textBox.ReadOnly == true)
|
|
|
|
|
{
|
|
|
|
|
textBox.ReadOnly = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-09-13 12:53:53 +04:00
|
|
|
|
{
|
|
|
|
|
textBox.ReadOnly = true;
|
|
|
|
|
}
|
2023-09-26 20:44:05 +04:00
|
|
|
|
}
|
2023-09-26 09:42:55 +04:00
|
|
|
|
|
2023-09-26 21:38:38 +04:00
|
|
|
|
private void TextBox_TextChanged(object sender, EventArgs e)
|
2023-09-26 20:44:05 +04:00
|
|
|
|
{
|
2023-09-26 21:38:38 +04:00
|
|
|
|
_textChanged?.Invoke(sender, e);
|
2023-09-13 12:53:53 +04:00
|
|
|
|
}
|
2023-09-13 11:57:01 +04:00
|
|
|
|
}
|
|
|
|
|
}
|