2013-12-10 47 views
-5

我想知道如何能夠將文本框中的值添加到標籤中,而不會在每次添加另一個比薩時將標籤重置爲零。我基本上需要代碼才能顯示如何繼續增加文本框值添加到標籤將文本框中的值添加到標籤

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(); 
      } 
     } 
+5

提示可能有助於未來:您的緊迫感是(1)沒有什麼特別之處,(2)不會贏得任何積分。獲得快速響應的最佳選擇是制定一個非常清晰,明確,高質量的問題。 – dmckee

+0

在這裏你的代碼中有一些複製粘貼錯誤。你能否清理一下,重點是精確地縮小你有問題的地方? – paqogomez

+0

非常感謝, –

回答

1

我相信你正在嘗試做的是將值添加到PizzaPrice,然後附加到前面的£標誌上txtPizzaPrice.Text顯示。

PizzaPrice應該是property rather than a field

public double PizzaPrice { get; set; } 

請注意,我+=價值比薩餅的價格,然後在文本屬性顯示出來:

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(); 
    } 
} 

你可以做很多事情來縮短你的代碼。嘗試將比薩類型添加到單選按鈕的Tag,並使用一個結構體作爲比薩值。但我會把它留給你。

+1

非常感謝,這正是我需要的@paqogomez –

相關問題