COP-17/WinFormsProject/WinFormsLibrary/NumberTextBox.cs

80 lines
1.8 KiB
C#
Raw Normal View History

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-09-21 10:49:09 +04:00
public int maxValue;
public int minValue;
public bool error = false;
public NumberTextBox()
{
InitializeComponent();
2023-09-21 10:49:09 +04:00
}
//публичное свойство
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;
}
}
}