2024-09-17 00:38:06 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2024-09-17 12:41:48 +04:00
|
|
|
|
using Library15Gerimovich.Exceptions;
|
2024-09-17 00:38:06 +04:00
|
|
|
|
|
|
|
|
|
namespace Library15Gerimovich
|
|
|
|
|
{
|
|
|
|
|
public partial class InputRealNumber : UserControl
|
|
|
|
|
{
|
2024-09-17 12:41:48 +04:00
|
|
|
|
private event EventHandler? _valueChanged;
|
|
|
|
|
|
2024-09-17 00:38:06 +04:00
|
|
|
|
public InputRealNumber()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2024-09-17 12:41:48 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка и получение введенного значения
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int? IntValue
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (IsNullCheckBox.Checked)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(MainTextBox.Text))
|
|
|
|
|
{
|
|
|
|
|
throw new EmptyValueException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ParsedInt;
|
|
|
|
|
if (Int32.TryParse(MainTextBox.Text, out ParsedInt))
|
|
|
|
|
{
|
|
|
|
|
return ParsedInt;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new MalformedRealException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetNullState(value is null, true);
|
|
|
|
|
if (value is not null)
|
|
|
|
|
{
|
|
|
|
|
MainTextBox.Text = value.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Событие, вызываемое при смене значения (либо при смене CheckBox)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event EventHandler? ValueChanged
|
|
|
|
|
{
|
|
|
|
|
add { _valueChanged += value; }
|
|
|
|
|
remove { _valueChanged -= value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetNullState(bool IsNull, bool ClearText = false)
|
|
|
|
|
{
|
|
|
|
|
IsNullCheckBox.Checked = IsNull;
|
|
|
|
|
MainTextBox.Enabled = !IsNull;
|
|
|
|
|
|
|
|
|
|
if (ClearText)
|
|
|
|
|
{
|
|
|
|
|
MainTextBox.Text = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void IsNullCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SetNullState(IsNullCheckBox.Checked);
|
|
|
|
|
_valueChanged?.Invoke(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_valueChanged?.Invoke(this, e);
|
|
|
|
|
}
|
2024-09-17 00:38:06 +04:00
|
|
|
|
}
|
|
|
|
|
}
|