-5

I wanted to know how I would be able to keep adding the values from the textbox to a label, without the label resetting to zero every time I add another Pizza I basically need code showing me how to add keep adding text box value to a label

private void SummaryBox_TextChanged(object sender, EventArgs e)//Textbox:the value is shown of the pizza selected
        {

        }

        private void txtPizzaPrice_TextChanged(object sender, EventArgs e)
        {

        }
        Menu(object sender, System.ComponentModel.CancelEventArgs e)
{


        private void lblPrice_Click(object sender, EventArgs e)
        {
            // Label where the Pizza prices needs to be added up each time I press add pizza
        }

    }
}

//HERE ARE THE PIZZA VALUES

      double PizzaPrice;//Global


 double ExtraTopping;//Global

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            string CT;



            if (radioButton2.Enabled == true) //PIZZA CHEESE TOMATO
            {
                double ctp = 3.50;
                PizzaPrice = ctp;

                txtPizzaPrice.Text = "£ " + PizzaPrice.ToString(); //Value I want //to add to lblPrice

                CT = radioButton2.Text;

                SummaryBox.Text = CT;


            }
            else
            {
                SummaryBox.Clear();
            }

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            string VS;

            if (radioButton1.Enabled == true) //PIZZA Veg SUpreme
            {
                double vsp = 5.20;
                PizzaPrice = vsp;

                txtPizzaPrice.Text = "£ " + PizzaPrice.ToString(); //Value I want //to add to lblPrice

                VS = radioButton1.Text;

                SummaryBox.Text = VS;

            }
            else
            {
                SummaryBox.Clear();
            }

        }

        private void radioButton3_CheckedChanged_1(object sender, EventArgs e)
        {
            string SV;


            if (radioButton3.Enabled == true) //PIZZA SPicy Veg
            {
                double svp = 5.20;
                PizzaPrice = svp;

                txtPizzaPrice.Text = "£ " + PizzaPrice.ToString(); //Value I want //to add to lblPrice

                SV = radioButton3.Text;

                SummaryBox.Text = SV;


            }
            else
            {
                SummaryBox.Clear();  
            }
        }

        private void radioButton6_CheckedChanged(object sender, EventArgs e)
        {
            string MF;

            if (radioButton6.Enabled == true) //PIZZA Veg SUpreme
            {
                double mfp = 5.80;
                PizzaPrice = mfp;

                txtPizzaPrice.Text = "£ " + PizzaPrice.ToString(); //Value I want //to add to lblPrice

                MF = radioButton6.Text;

                SummaryBox.Text = MF;
            }
            else 
            {
                SummaryBox.Clear();
            }
        }

        private void radioButton7_CheckedChanged(object sender, EventArgs e)
        {
            string HP;

            if (radioButton7.Enabled == true) //PIZZA Ham pineapple
            {
                double hpp = 4.20;
                PizzaPrice = hpp;

                txtPizzaPrice.Text = "£ " + PizzaPrice.ToString();
                ^ Value I want to add to lblPrice^

                HP = radioButton7.Text;

                SummaryBox.Text = HP;

            }
            else
            {
                SummaryBox.Clear();

            }
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            string SF;

            if (radioButton4.Enabled == true) // PIZZA Veg SUpreme
            {
                double sfp = 5.60;
                PizzaPrice = sfp;

                txtPizzaPrice.Text = "£ " + PizzaPrice.ToString(); //Value I want //to add to lblPrice

                SF = radioButton4.Text;

                SummaryBox.Text = SF;

            }
            else
            {
                SummaryBox.Clear();
            }
        }
Ali AK
  • 1
  • 6

1 Answers1

1

I believe what you are trying to do is to add a value to PizzaPrice, then display it on txtPizzaPrice.Text with the £ sign appended to the front.

PizzaPrice should be a property rather than a field.

public double PizzaPrice { get; set; }

Notice that I += the value to pizza price, then display it on the text property:

private void radioButton7_CheckedChanged(object sender, EventArgs e)
{
    if (radioButton7.Checked)
    {
        double hpp = 4.20;
        PizzaPrice += hpp;
        txtPizzaPrice.Text = "£ " + PizzaPrice.ToString();
        SummaryBox.Text = radioButton7.Text;
    }
    else
    {
        SummaryBox.Clear();
    }
}

You could do a lot to shorten your code. Try adding the pizza type to the Tag of the radio button, and using a struct for your pizza values. But I'll leave that to you.

Community
  • 1
  • 1
crthompson
  • 14,783
  • 6
  • 51
  • 74