• Задана форма. Как вписать проверку параметров?  То есть,  например, диаметр отверстия не должен быть больше самой плиты. 
    using System;
    using System.Windows.Forms;

    namespace Form1Namespace
    {
    public partial class Form1
    {
    public Form1()
    {
    InitializeComponent();
    }


    private void Form1_Load(object sender, System.EventArgs e)
    {

    }



    private void button1_Click(object sender, System.EventArgs e)
    {
    //Начальные параметры плиты
    textBox1.Text = "35";
    textBox2.Text = "40";
    textBox3.Text = "22";
    textBox4.Text = "30";
    textBox5.Text = "30";
    textBox6.Text = "10";
    textBox7.Text = "8";
    textBox8.Text = "7";
    textBox9.Text = "18";
    textBox10.Text = "8";
    textBox11.Text = "10";

    }

    private void button2_Click(object sender, System.EventArgs e)
    {
    if ((textBox1.Text != "")&&(textBox2.Text != "")&&(textBox3.Text != "")
    &&(textBox4.Text != "")&&(textBox5.Text != "")&&(textBox6.Text != "")
    &&(textBox7.Text != "")&&(textBox8.Text != "")&&(textBox9.Text != "")
    &&(textBox10.Text != "")&&(textBox11.Text != ""))
    {
    int p1 = int.Parse(textBox1.Text);
    int p2 = int.Parse(textBox2.Text);
    int p3 = int.Parse(textBox3.Text);
    int p4 = int.Parse(textBox4.Text);
    int p5 = int.Parse(textBox5.Text);
    int p6 = int.Parse(textBox6.Text);
    int p7 = int.Parse(textBox7.Text);
    int p8 = int.Parse(textBox8.Text);
    int p9 = int.Parse(textBox9.Text);
    int p10 = int.Parse(textBox10.Text);
    int p11 = int.Parse(textBox11.Text);
    //Метод создания плиты
    NewMacroNamespace.NewMacroClass.Plita(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11);
    }
    else
    MessageBox.Show("Заполните все поля!","Внимание",MessageBoxButtons.OK,MessageBoxIcon.Error);

    }


    }
    }




Ответы 1

  • не забывайте использовать автоформатирование CTRL+K+D using System;using System.Windows.Forms;namespace Form1Namespace{    public partial class Form1    {        public Form1()        {            InitializeComponent();        }        private void Form1_Load(object sender, System.EventArgs e)        {            //Начальные параметры плиты            // во первых названия должны быть не textBox1, а tbPlateWidth и тп, а то черт разберешь что куда            textBox1.Text = "35";            textBox2.Text = "40";            textBox3.Text = "22";            textBox4.Text = "30";            textBox5.Text = "30";            textBox6.Text = "10";            textBox7.Text = "8";            textBox8.Text = "7";            textBox9.Text = "18";            textBox10.Text = "8";            textBox11.Text = "10";        }        private void button2_Click(object sender, System.EventArgs e)        {            // лучше писать в виде фильтров , а не многовложенных условий            if ((textBox1.Text = "") || (textBox2.Text = "") || (textBox3.Text = "")            || (textBox4.Text = "") || (textBox5.Text = "") || (textBox6.Text = "")            || (textBox7.Text = "") || (textBox8.Text = "") || (textBox9.Text = "")            || (textBox10.Text = "") || (textBox11.Text = ""))            {                MessageBox.Show("Заполните все поля!", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Error);                return;            }            var PlateWidth = int.Parse(textBox1.Text);            var PlateDiametr = int.Parse(textBox2.Text);            var p3 = int.Parse(textBox3.Text);            var p4 = int.Parse(textBox4.Text);            var p5 = int.Parse(textBox5.Text);            var p6 = int.Parse(textBox6.Text);            var p7 = int.Parse(textBox7.Text);            var p8 = int.Parse(textBox8.Text);            var p9 = int.Parse(textBox9.Text);            var p10 = int.Parse(textBox10.Text);            var p11 = int.Parse(textBox11.Text);            //пример проверки            if PlateDiametr > PlateWidth {                MessageBox.Show("диаметр отверстия не должен быть больше самой плиты", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Error);                return;            }            //Метод создания плиты            NewMacroNamespace.NewMacroClass.Plita(PlateWidth, PlateDiametr, p3, p4, p5, p6, p7, p8, p9, p10, p11);        }    }}
    • Автор:

      stephen
    • 6 лет назад
    • 0
  • Добавить свой ответ

Еще вопросы

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years