【发布时间】:2016-11-03 17:55:45
【问题描述】:
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这句话吗?
-
命中:使用
if比较y和year.Length。
标签: c# button messagebox