“当用户点击”添加您的分数“菜单项时,将每种类型的饮品的分数添加到饮品的总数,清除文本框,然后重置焦点。”
我一直试图弄清楚如何添加上面引用的内容。我认为我过度思考并使其变得比实际更难。
这是我到目前为止所做的:
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;
}
}
}
答案 0 :(得分:1)
嗯,这是个大问题。我将通过指出您在不存储返回值的情况下调用Convert
来提供帮助。
您有类似Convert.ToInt32(PrunePunchTextBox.Text);
而不是var value = Convert.ToInt32(PrunePunchTextBox.Text);
的内容。
希望有所帮助!
答案 1 :(得分:0)
不要在表单的开头声明int。只需拖放一个从0开始的标签,每个分数都会将其加起来。将标签转换为整数,并使用+ =为其添加值。
(P.S。你有一个我可以继续工作的项目吗?)