简体   繁体   English

为什么在我清除输出标签后这些值仍然相加?

[英]Why are the values still adding up after i clear the output label?

I'm not sure what is going on.我不确定发生了什么。 I thought I had it set up to clear the output label at the end.我以为我已将其设置为最后清除输出标签。 Everytime I clear it, the program still remembers the previous number and adds to it.每次我清除它时,程序仍然记得以前的数字并添加它。 I honestly have no idea what is going on.老实说,我不知道发生了什么。

Also on a side note, how do I put set up radiobuttons to be used in the this method?另外附带说明,如何设置要在此方法中使用的单选按钮?

First coding class so i'm still kind of a beginner.第一次编码课,所以我还是个初学者。

    private double oilandlube()
    {
        if (checkBox1.Checked == true)
        {
            Oil_change = 26;
        }
        if (checkBox2.Checked == true)
        {
            Lube_job = 18;
        }
        return Oil_change + Lube_job;
    }
    private void Oiltype ()
    {
        if (radioButton1.Checked)
        {
            Regular = 0;
        }
        if (radioButton2.Checked)
        {
            Mixed = 10;
        }
        else
        {
            Mixed = 0;
        }
        if (radioButton3.Checked)
        {
            Full_Synthetic = 18;
        }
        else
        {
            Full_Synthetic = 0;
        }
    }
    private void carwash()
    {
        if (radioButton4.Checked)
        {
            none = 0;
        }
        if (radioButton5.Checked)
        {
            complimentary = 0;
        }
        if (radioButton6.Checked)
        {
            Full_service = 6;
        }
        else
        {
            Full_service = 0;
        }
        if (radioButton7.Checked)
        {
            Premium = 9;
        }
        else
        {
            Premium = 0;
        }

    }
    private double flushes()
    {
        if (checkBox3.Checked == true)
        {
            Radiator_flush = 30;
        }

        if (checkBox4.Checked == true)
        {
            Transmission_flush = 80;
        }

        return Radiator_flush + Transmission_flush;
    }
    private double misc()
    {
        if (checkBox5.Checked == true)
        {
            inspection = 15;
        }

        if (checkBox6.Checked == true)
        {
            replace_muffler = 100;
        }

        if (checkBox7.Checked == true)
        {
            tire_rotation = 20;
        }
        return inspection + replace_muffler;
    }
    private double partsandlabor()
    {

       double.TryParse(textBox1.Text, out parts);
       double.TryParse(textBox2.Text, out labor);

       return parts + labor; 

    }

    private double tax()
    {
        return partsandlabor() * taxes;
    }



    private void summary()
    {
        service = oilandlube() + flushes() + misc();
        total_parts = partsandlabor();
        double total_tax = tax();
        double grand_total = service + total_parts + total_tax;

        label7.Text = service.ToString("c");
        label8.Text = total_parts.ToString("c");
        label9.Text = total_tax.ToString("c");
        label10.Text = grand_total.ToString("c");

    }


    private void button3_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        oilandlube();
        carwash();
        flushes();
        misc();
        partsandlabor();
        summary();
    }
    private void ClearOilandlube()
    {
        checkBox1.Checked = false;
        checkBox2.Checked = false;
    }
    private void ClearMisc()
    {
        checkBox5.Checked = false;
        checkBox6.Checked = false;
        checkBox7.Checked = false;
    }
    private void ClearFlushes()
    {
        checkBox3.Checked = false;
        checkBox4.Checked = false;
    }

    private void ClearSummary()
    {
        label7.Text = "";
        label8.Text = "";
        label9.Text = "";
        label10.Text = "";
    }
    private void button2_Click(object sender, EventArgs e)
    {

        ClearOilandlube();
            ClearMisc();
            ClearFlushes();
            ClearSummary();



        radioButton1.Checked = false;
        radioButton2.Checked = false;
        radioButton3.Checked = false;
        radioButton4.Checked = false;
        radioButton5.Checked = false;
        radioButton6.Checked = false;
        radioButton7.Checked = false;
        textBox1.Text = "0";
        textBox2.Text = "0";

    }
}

} }

When you clear the contents of your controls, you should also clear the values of the backing variables, so they don't retain their previous values.当您清除控件的内容时,您还应该清除支持变量的值,这样它们就不会保留以前的值。 You should be able to just set them back to zero in your Clear methods.您应该能够在Clear方法中将它们设置回零。

For example, oil and lube might look like:例如,油和润滑油可能如下所示:

private void ClearOilandlube()
{
    checkBox1.Checked = false;
    checkBox2.Checked = false;
    Oil_change = 0;
    Lube_job = 0;
    Mixed = 0;
    Regular = 0;
    Full_Synthetic = 0;
}

It looks like you're holding state of some your variables globally so you can access them elsewhere.看起来您正在全局保存某些变量的状态,以便您可以在其他地方访问它们。

Mixed = 10;

You'll have to reset that to some default value as well.您还必须将其重置为某个默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 添加 3 个标签控件的值以在另一个标签控件中输出结果时出错 - Error with adding values of 3 label controls to output result in another label control 将多个复选框值添加到标签,基于它们是否被选中C# - Adding up Multiple Checkbox values to a label, Based on if they are Checked or notC# 循环后将输入返回到相邻的输出标签以计算值 - Return input to adjacent output label after loop to calculate values 仍然不清楚为什么所有的船只在旋转后都没有向它们所面对的方向移动? - Still not clear yet why all the ships are not moving to the direction they are facing after rotation? 如何清除Bing地图中的所有图钉,之后仍然可以添加更多图钉? - How can I clear all the pushpins from my Bing Map and still be able to add more after that? 如何在asp.net中的代码后面一段时间后清除标签文本? - How can I clear label text after some amount of time from code behind in asp.net? 为什么DEBUG仍在写输出? - Why is DEBUG still writing to Output? 为什么该程序仍然输出“ not null”? - why this program still output “not null”? 提交后清除网络表单上的值 - Clear the values on a webform after submitting 为什么我添加到ResourceDictionary 后还是找不到资源? - Why still can't find the resource after I add it into ResourceDictionary?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM