Проверка на правильность ввода в numericUpDown

thmn8

Администратор
Сообщения
1 472
Реакции
311
Сайт
tehadm.ru
C#:
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.label1.Text = "";
            this.numericUpDown1.Maximum = 10;
            this.numericUpDown1.TextChanged += numericUpDown1_TextChanged;
        }
        
        void numericUpDown1_TextChanged(object sender, EventArgs e)
        {
            if (!Valid(this.numericUpDown1.Text))
                this.label1.Text = "Попытка ввесни не верное значение";
            else
                this.label1.Text = "";
        }
 
        bool Valid(string text)
        {
            int i = 0;
            if (!int.TryParse(text, out i))
            return false;
            if (i < 0 || i > 10)
                return false;
            else return true;
        }
    }
 
Назад
Верх Низ