There are a lot of ways you could do this. Here's one:
Handle all Panel positioning in the Click EventHandler of one Button:
private void YourForm_Load(object sender, EventArgs e)
{
Panels = new List<Panel> {panel1, panel2, panel3};
}
private List<Panel> Panels;
private int currentPanelIndex = 0;
private Panel currentPanel;
private void PanelChangeButton_Click(object sender, EventArgs e)
{
currentPanelIndex =
(currentPanelIndex == 2)
? 0
: ++currentPanelIndex;
currentPanel = Panels[currentPanelIndex];
currentPanel.BringToFront();
switch (currentPanel.Name)
{
case "panel1":
break;
case "panel2":
break;
case "panel3":
break;
}
}
}
We keep track of the current Panel, and, with each click on the 'PanelChangeButton, we set the index to point to the next Panel in the series. If we are at the last Panel in the series, we reset the index to point to the first Panel.
In the 'switch/case statements you can write your code to do whatever based on the (new) current panel.
fyi: this code is redundant:
var point = new Point(97,76);
this.panel2.Location = point;
this.panel2.Location = new Point(
this.panel2.Location.X,
this.panel2.Location.Y);
It can be replaced with this:
this.panel2.Location = new Point(97,76);