关键代码:
第一次用FORM,感觉还是很刺激哟。
1 double total = 0.0d; 2 private void MainFormLoad(object sender, EventArgs e) 3 { 4 cbxType.Items.AddRange(new object[] {"正常收费","打八折","打七折","打五折"}); 5 cbxType.SelectedIndex = 0; 6 } 7 8 void Button1Click(object sender, System.EventArgs e) 9 { 10 double totalPrices = 0d; 11 switch(cbxType.SelectedIndex) 12 { 13 case 0: 14 totalPrices = Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text); 15 break; 16 case 1: 17 totalPrices = Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text) * 0.8; 18 break; 19 case 2: 20 totalPrices = Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text) * 0.7; 21 break; 22 case 3: 23 totalPrices = Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text) * 0.5; 24 break; 25 } 26 //double totalPrices = Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text); 27 total = total + totalPrices; 28 lbxList.Items.Add("单价: " + txtPrice.Text + " 数量: " + txtNum.Text + " 合计: " + totalPrices.ToString()); 29 lblResult.Text = total.ToString(); 30 } 31 32 void Button2Click(object sender, EventArgs e) 33 { 34 txtPrice.Text = Convert.ToString(0.00); 35 txtNum.Text = Convert.ToString(0); 36 lblResult.Text = Convert.ToString(0.00); 37 lbxList.Items.Clear();
输出界面,反复赏析,呵呵: