80 lines
1.8 KiB
C#
80 lines
1.8 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.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace WinFormsLibrary
|
|
{
|
|
public partial class NumberTextBox : UserControl
|
|
{
|
|
public int maxValue;
|
|
public int minValue;
|
|
public bool error = false;
|
|
|
|
public NumberTextBox()
|
|
{
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
|
//публичное свойство
|
|
public string Selected
|
|
{
|
|
get
|
|
{
|
|
if (minValue == null)
|
|
{
|
|
error = true;
|
|
}
|
|
|
|
if (maxValue == null)
|
|
{
|
|
error = true;
|
|
}
|
|
|
|
if (Check_Value(Convert.ToInt32(numericUpDown.Value)))
|
|
{
|
|
return "";
|
|
}
|
|
return numericUpDown.Value.ToString();
|
|
}
|
|
set
|
|
{
|
|
if (!Check_Value(Convert.ToInt32(numericUpDown.Value)))
|
|
{
|
|
error = true;
|
|
}
|
|
numericUpDown.Value = 0;
|
|
}
|
|
}
|
|
|
|
public void SetMaxValue(int number) // переделать через свойство
|
|
{
|
|
numericUpDown.Maximum = number;
|
|
maxValue = number;
|
|
}
|
|
|
|
public void SetMinValue(int number) // переделать через свойство
|
|
{
|
|
numericUpDown.Minimum = number;
|
|
minValue = number;
|
|
}
|
|
|
|
public bool Check_Value(int number)
|
|
{
|
|
if (number < numericUpDown.Minimum || number > numericUpDown.Maximum)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|