0

我是 C# 编码的新手。目前我遇到了根据点击textBox次数填充 a 的问题。button1我已经能够填充选项一,但我不确定如何在第二次点击后获得第二个选项,所以第四次。我怎么能做到这一点?另外,我需要在第四次点击后添加一个循环重新开始吗?

代码

protected void Button1_Click(object sender, EventArgs e)
{
     MyTextBox.Text = "Fruits"; //1st click
     MyTextBox.Text = "Vegtables"; //2nd click
     MyTextBox.Text = "Grains"; //3rd click
     MyTextBox.Text = "Poultry"; //4th click

}
4

1 回答 1

0
private List<string> messages= new List<string>(){"Fruits", "Vegetables", "Grains", "Poultry"};
private int clickCount = 0;

protected void Button1_Click(object sender, EventArgs e)
{
   MyTextBox.Text = messages[clickCount];
   clickCount++;
   if (clickCount == messages.Count)
      clickCount = 0;

}
于 2012-10-24T04:07:50.493 回答