我有4个标签,可见性设置为false,还有一个按钮。每次我点击按钮,我都希望它能给我看一个不同的标签。有人可以告诉我这个代码吗?
答案 0 :(得分:6)
为此任务量身定制Queue
。
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
}