81 lines
2.0 KiB
C#
81 lines
2.0 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;
|
|
using VisualComponentsLib.CustomException;
|
|
|
|
namespace VisualComponentsLib
|
|
{
|
|
public partial class MyTextBox : UserControl
|
|
{
|
|
public string? TextBoxValue
|
|
{
|
|
get
|
|
{
|
|
if (checkBox.Checked)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (textBox.Text.Length <= 2)
|
|
{
|
|
throw new TextBoxException("Число не введено");
|
|
}
|
|
|
|
if (textBox.Text.Contains('.') && textBox.Text.IndexOf('.') != textBox.Text.Length - 1)
|
|
{
|
|
return textBox.Text;
|
|
}
|
|
|
|
throw new TextBoxException("Некорретный формат числа");
|
|
}
|
|
|
|
set
|
|
{
|
|
if (!checkBox.Checked && value == null)
|
|
{
|
|
throw new TextBoxException("Недопустимое значение null");
|
|
}
|
|
|
|
textBox.Text = value;
|
|
}
|
|
}
|
|
|
|
public MyTextBox()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private EventHandler _textChanged;
|
|
|
|
public new event EventHandler? TextChanged
|
|
{
|
|
add => _textChanged += value;
|
|
remove => _textChanged -= value;
|
|
}
|
|
|
|
private void CheckBox_CheckedChanged_1(object sender, EventArgs e)
|
|
{
|
|
if (textBox.ReadOnly == true)
|
|
{
|
|
textBox.ReadOnly = false;
|
|
}
|
|
else
|
|
{
|
|
textBox.ReadOnly = true;
|
|
}
|
|
}
|
|
|
|
private void TextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
_textChanged?.Invoke(sender, e);
|
|
}
|
|
}
|
|
}
|