2023-09-20 23:39:46 +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;
|
|
|
|
|
|
|
|
|
|
namespace WinFormsLibrary
|
|
|
|
|
{
|
|
|
|
|
public partial class NumberTextBox : UserControl
|
|
|
|
|
{
|
2023-10-04 22:43:22 +04:00
|
|
|
|
public int? maxValue = null;
|
|
|
|
|
public int? minValue = null;
|
2023-09-21 10:49:09 +04:00
|
|
|
|
public bool error = false;
|
|
|
|
|
|
2023-09-20 23:39:46 +04:00
|
|
|
|
public NumberTextBox()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-09-21 10:49:09 +04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 22:43:22 +04:00
|
|
|
|
public int? MinValue
|
|
|
|
|
{
|
|
|
|
|
get { return minValue; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null) return;
|
|
|
|
|
minValue = value;
|
|
|
|
|
numericUpDown.Minimum = (int)value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-21 10:49:09 +04:00
|
|
|
|
|
2023-10-04 22:43:22 +04:00
|
|
|
|
public int? MaxValue
|
2023-09-21 10:49:09 +04:00
|
|
|
|
{
|
2023-10-04 22:43:22 +04:00
|
|
|
|
get { return maxValue; }
|
|
|
|
|
set
|
2023-09-21 10:49:09 +04:00
|
|
|
|
{
|
2023-10-04 22:43:22 +04:00
|
|
|
|
if (value == null) return;
|
|
|
|
|
maxValue = value;
|
|
|
|
|
numericUpDown.Maximum = (int)value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-21 10:49:09 +04:00
|
|
|
|
|
2023-10-04 22:43:22 +04:00
|
|
|
|
public decimal Value
|
|
|
|
|
{
|
|
|
|
|
get { return numericUpDown.Value; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (MinValue == null || MaxValue == null)
|
2023-09-21 10:49:09 +04:00
|
|
|
|
{
|
|
|
|
|
error = true;
|
2023-10-04 22:43:22 +04:00
|
|
|
|
return;
|
2023-09-21 10:49:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 22:43:22 +04:00
|
|
|
|
if (value < MinValue || value > MaxValue)
|
2023-09-21 10:49:09 +04:00
|
|
|
|
{
|
|
|
|
|
error = true;
|
2023-10-04 22:43:22 +04:00
|
|
|
|
return;
|
2023-09-21 10:49:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 22:43:22 +04:00
|
|
|
|
numericUpDown.Value = value;
|
|
|
|
|
}
|
2023-09-21 10:49:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 22:43:22 +04:00
|
|
|
|
public event EventHandler DateChanged
|
2023-09-21 10:49:09 +04:00
|
|
|
|
{
|
2023-10-04 22:43:22 +04:00
|
|
|
|
add { numericUpDown.ValueChanged += value; }
|
|
|
|
|
remove { numericUpDown.ValueChanged -= value; }
|
2023-09-20 23:39:46 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|