I'm trying to make multiple pages on the form using panel control in c#. First i set the index variable inside the class Form1
List<Panel> listPanel = new List<Panel>();
int index;
And to go back and forward i created buttons. To go to the next panel:
private void btnNext_Click(object sender, EventArgs e)
{
if (index < listPanel.Count - 1)
listPanel[++index].BringToFront();
}
And for going back:
private void btnBack_Click(object sender, EventArgs e)
{
if (index > 0)
listPanel[--index].BringToFront();
}
And this set of codes to decide which panel should be seen on top according to index:
private void Form1_Load(object sender, EventArgs e)
{
listPanel.Add(panel1);
listPanel.Add(panel2);
listPanel.Add(panel3);
listPanel[index].BringToFront();
}
But it doesn't work. I can not go to next or previous panel by clicking the buttons. Where am i doing wrong?