What fastestindian suggested is spot on; however, an alternative for a cleaner interface is to use UserControls to populate a panel instead of separate forms.
For example...
- public class WizardPanel : UserControl { ... }
Now you can create a bunch of WizardPanel objects and design them using designer to look like however you want.
- public class MyPanel1 : WizardPanel { ... }
-
public class MyPanel2 : WizardPanel { ... }
-
public class MyPanel3 : WizardPanel { ... }
- public class Wizard
-
{
-
private List<WizardPanel> m_panelList = new List<WizardPanel>();
-
private int m_currentIndex = 0;
-
-
public void Add(WizardPanel panelToAdd) { ... }
-
public void Remove(WizardPanel panelToRemove { ... }
-
public void Remove(int index) { ... }
-
public WizardPanel Get(int index) { ... }
-
public WizardPanel GetFirst() { ... }
-
public WizardPanel GetNext() { ... }
-
public WizardPanel GetLast() { ... }
-
public WizardPanel GetPrev() { ... }
-
}
Create a Wizard object as a private member in your main form. Also throw two panels onto your form. Dock one to fill and the other to the bottom. Put a next/back button in the lower button.
In your constructor, you can put...
- myWizard.Add(new MyPanel1());
-
myWizard.Add(new MyPanel2());
-
myWizard.Add(new MyPanel3());
-
-
mainPanel.Controls.Clear();
-
mainPanel.Controls.Add(myWizard.GetFirst());
Your next button's click event ...
- mainPanel.Controls.Clear();
-
mainPanel.Controls.Add(myWizard.GetNext());
... and the back button ...
- mainPanel.Controls.Clear();
-
mainPanel.Controls.Add(myWizard.GetPrev());
This is just a stubbed out, bare bones version of a way to get the functionality you want inside a single form instead of instantiating new ones. It may not be what you need (as I said, I think fastestindian's answer is the best solution for what you described) but it's always fun to think about other ways to go about it :)
Good luck!