多按钮按下

时间:2012-12-19 14:40:53

标签: c# button

我有4个标签,可见性设置为false,还有一个按钮。每次我点击按钮,我都希望它能给我看一个不同的标签。有人可以告诉我这个代码吗?

1 个答案:

答案 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
}