Adding values from textbox to label [closed]

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.

Leave a Comment