如何添加分数和总分
本文关键字:添加 何添加 | 更新日期: 2023-09-27 18:35:17
" 当用户单击"添加您的分数"菜单项时,将每种饮料的分数添加到饮料的总数中,清除文本框,然后重置焦点。
我试图弄清楚如何添加上面引用的内容。我想我想太多了,让它比实际情况更难。
以下是我到目前为止所做的:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Lab6
{
public partial class NewTester : Form
{
private int AppleAde;
private decimal TotalScore;
private string Winner_Name = "";
int PrunePunch_Score;
int Total_Num_Of_Tasters;
decimal Average_Rating_Of_Each_Drink;
//private decimal Total_Score;
public NewTester()
{
Thread t = new Thread(new ThreadStart(SplashStart));
t.Start();
Thread.Sleep(5000);
InitializeComponent();
t.Abort();
}
public void SplashStart() {
Application.Run(new Form2());
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Lab6 by J Soto 'nThis lab was started on 10/9/13","About Lab 6",MessageBoxButtons.OK);
}
private void addYourScoresToolStripMenuItem_Click(object sender, EventArgs e)
{ // Vars for text box values...
PrunePunch_Score = Convert.ToInt32(PrunePunchTextBox.Text);
AppleAde = Convert.ToInt32(AppleAdeTextBox.Text);
//...
if ((PrunePunch_Score <= 10) && (PrunePunch_Score >= 0))
Convert.ToInt32(PrunePunchTextBox.Text);
else
MessageBox.Show("Please enter a number between 0 and 10","Prune Punch");
if ((AppleAde <= 10) && (PrunePunch_Score >= 0))
Convert.ToInt32(AppleAdeTextBox.Text);
else
MessageBox.Show("Please enter a number betwen 0 and 10","Apple Ade");
//...
}
private void PrunePunchTextBox_TextChanged(object sender, EventArgs e)
{
PrunePunch_Score = Convert.ToInt32(PrunePunchTextBox.Text);
}
private void AppleAdeTextBox_TextChanged(object sender, EventArgs e)
{
AppleAde = Convert.ToInt32(AppleAdeTextBox.Text);
}
private void summaryToolStripMenuItem_Click(object sender, EventArgs e)
{
string Summary;
// Summary= "Winner:"+ Winner_Name "Total Number of Taste Testers:" + Total_Num_Of_Tasters "Average rating for each drink:" + Average_Rating_Of_Each_Drink;
}
}
}
嗯,这是一个大问题。我将通过指出您在不存储返回值的情况下调用Convert
来提供帮助。
你有像Convert.ToInt32(PrunePunchTextBox.Text);
而不是var value = Convert.ToInt32(PrunePunchTextBox.Text);
这样的东西。
希望对您有所帮助!
不要在窗体的开头声明 int。 只需拖放一个从 0 开始的标签。 每个分数都会加起来。 将标签转换为整数并使用 += 为其添加值。
(附言你有一个我可以做的项目的稀有吗?