我试图建立一个使用C#的考试平地机。我对此很陌生,不太了解。我将使用哪些代码添加最小和最大按钮并添加标签,说明它是最小值还是最大值?最小和最大按钮和标签
private void btnAdd_Click(object sender, EventArgs e)
{
int points;
try
{
points = int.Parse(txtPoints.Text);
lstPoints.Items.Add(points);
txtPoints.Clear();
txtPoints.Focus();
if (lstPoints.Items.Count == 12)
{
txtPoints.Enabled = false;
btnAdd.Enabled = false;
}
if (lblResult.Text != "")
{
lblResult.Text = "";
}
}
catch
{
MessageBox.Show("Please enter only whole numbers");
txtPoints.Clear();
txtPoints.Focus();
}
}
private void btnAvg_Click(object sender, EventArgs e)
{
double total = 0;
for (int i = 0; i < lstPoints.Items.Count; i++)
{
total += (int)lstPoints.Items[i];
}
total /= lstPoints.Items.Count;
lblResult.Text = total.ToString();
}
private void btnClear_Click(object sender, EventArgs e)
{
lstPoints.Items.Clear();
txtPoints.Enabled = true;
btnAdd.Enabled = true;
}
}
}
'lstPoints.Items [i]'的类型是什么? – Ofiris 2014-10-02 04:51:52
哪条线发生异常? – Neel 2014-10-02 04:53:22
它发生在这一行总数+ =(double)lstPoints.Items [i]; – Strongbad2143 2014-10-02 04:54:42