Как получить доступ к переменным, которые хранят информацию о текстовом поле для нового метода в c#? - PullRequest
0 голосов
/ 15 февраля 2020

Я немного заржавел с C#, но я пытаюсь взять форму windows, ввести числа в текстовые поля, сохранить эти числа в переменные, преобразовать эти переменные из строки в int, затем взять эти переменные и поместите их в новый метод "CalculateGas" для расчета. Я собирался использовать этот метод в разделе click1.

Однако я не могу получить доступ ни к одной из переменных, которые я создал в этом коде. Для создания кода "private void textBox_TextChanged (object senter, EventArgs e)" я просто дважды щелкнул каждое текстовое поле в представлении конструктора. Я знаю, что здесь играет роль ключевое слово "private", но я не уверен, как чтобы обойти это ограничение и получить доступ к этим переменным, например, int "trips1Num" внутри textBox3_TextChanged.

    public void CalculateGas()
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {

    }

    private void textBox5_TextChanged(object sender, EventArgs e)
    {
        string collegeName1;
        collegeName1 = textBox5.Text;
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        string collegeName2;
        collegeName2 = textBox1.Text;
    }

    private void textBox8_TextChanged(object sender, EventArgs e)
    {
        string collegeState1;
        collegeState1 = textBox8.Text;
    }

    private void textBox14_TextChanged(object sender, EventArgs e)
    {
        string collegeState2;
        collegeState2 = textBox14.Text;
    }

    private void textBox3_TextChanged(object sender, EventArgs e)
    {
        string trips1;
        trips1 = textBox3.Text;
        int trips1Num = Int32.Parse(trips1);

    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {
        string trips2;
        trips2 = textBox2.Text;
        int trips2Num = Int32.Parse(trips2);
    }

    private void textBox10_TextChanged(object sender, EventArgs e)
    {
        string collegeDistance1;
        collegeDistance1 = textBox10.Text;
        int collegeDistance1Num = Int32.Parse(collegeDistance1);
    }

    private void textBox7_TextChanged(object sender, EventArgs e)
    {
        string collegeDistance2;
        collegeDistance2 = textBox7.Text;
        int collegeDistance2Num = Int32.Parse(collegeDistance2);
    }

    private void textBox9_TextChanged(object sender, EventArgs e)
    {
        string collegeFee1;
        collegeFee1 = textBox9.Text;
        int collegeFee1Num = Int32.Parse(collegeFee1);
    }

    private void textBox13_TextChanged(object sender, EventArgs e)
    {
        string collegeFee2;
        collegeFee2 = textBox13.Text;
        int collegeFee2Num = Int32.Parse(collegeFee2);
    }

    private void textBox4_TextChanged(object sender, EventArgs e)
    {
        string tuition1;
        tuition1 = textBox4.Text;
        int tuition1Num = Int32.Parse(tuition1);
    }

    private void textBox6_TextChanged(object sender, EventArgs e)
    {
        string tuition2;
        tuition2 = textBox6.Text;
        int tuition1Num = Int32.Parse(tuition2);
    }

    private void textBox12_TextChanged(object sender, EventArgs e)
    {
        string roomBoard1;
        roomBoard1 = textBox12.Text;
        int roomboard1Num = Int32.Parse(roomBoard1);
    }

    private void textBox11_TextChanged(object sender, EventArgs e)
    {
        string roomBoard2;
        roomBoard2 = textBox11.Text;
        int roomboard2Num = Int32.Parse(roomBoard2);
    }
...