0
public partial class Form1 : Form
{
string[] year = { "Year 1", "Year 2", "Year 3", "Year 4", "Year 5", "Year 6", "Year 7", "Year 8", "Year 9", "Year 10" };
static int y = 0;
public Form1()
{
InitializeComponent();
}
// the code for the progressBar in nextButton_Click was taken from http://www.codeproject.com/Articles/745453/Visual-Basic-Progress-Bar-control
private void nextButton_Click(object sender, EventArgs e)
{
progressBar1.PerformStep();
yearLabel.Text = year[y];
y = y + 1;
}
}
當我點擊「下一步」按鈕時,它到達「10年」後顯示錯誤消息(在WindowsFormsApplication1.exe中發生了'System.IndexOutOfRangeException'類型的未處理的異常)。如何在點擊按鈕上的最後一個命令時顯示消息?
我希望能夠在10年後點擊下一步按鈕,它會顯示一條消息,例如10年完成,遊戲結束等等。如何實現這一目標,任何幫助都將不勝感激。
你有沒有聽說過_if_? – Steve
命中:與'year.Length'相比,使用'if'來檢查'y'。 –