我試圖建立一個使用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