-5

我有 4 个可见性设置为 false 的标签和一个按钮。每次单击按钮时,我都希望它显示不同的标签。有人可以告诉我这个的代码吗?

4

1 回答 1

6

AQueue是为这项任务量身定做的。

private Queue<Label> queue = new Queue<Label>();
//add labels to queue in constructor

private void button1_Click(object sender, EventArgs e)
{
    queue.Peek().Visible = false; //hide label at the start of the queue
    queue.Enqueue(queue.Dequeue()); //move the first item to the end
    queue.Peek().Visible = true; //show the label at the start of the queue
}
于 2012-12-19T14:44:45.220 回答