在winform下点击一下按钮,希望值能加1
如:点击按钮一下,lable1.Text="aa",再点击一下lable.Text="bb",如此反复,类似于下一页的功能。
private void button1_Click(object sender, EventArgs e)
{
   string[] str=new string[]{"aa","bb","cc"}
   lable1.Text=str[i];////代码如何写
}
求实例代码WinForm下一页

解决方案 »

  1.   


    string[] str=new string[]{"aa","bb","cc"}
    int index = 0;private void button1_Click(object sender, EventArgs e)
    {
       lable1.Text=str[index];
       if(index <str.Length - 1)
          index ++;
       else
          index = 0;
    }
      

  2.   

    string[] str = new string[] { "aa", "bb", "cc" };
            int count = 0;
            private void button1_Click(object sender, EventArgs e)
            {
                if(count >= str.Length)
                {
                    count = count % str.Length;
                }
                this.label1.Text = str[count];
                count++;
            }