I've started working on a project that is basically a step by step wizard for creating a set of files for another program.
My form contains a panel that I have created a class for: MainPanel. MainPanel basically just sets the Size and Location. Each step used in the process is represented by a class that inherits from MainPanel. When the user clicks "Next" or "Back", I want to get rid of the current panel, and switch to the appropriate one.
I save all the data along the way in a Results class, so if necessary I can make a constructor to repopulate all the data on a "Back" click.
So my question is, what is the best way to get rid of the old panel and show the next one?
EDIT:
I'll leave a sample of some code with what I was thinking about doing. It works, but it seems like there's probably a better way to do it...
class MainForm
{
MainPanel mainPanel;
enum screens { FIRST, SECOND, THIRD };
screens currentScreen;
MainForm()
{
mainPanel = new firstPanel();
this.Controls.Add(mainPanel);
currentScreen = screens.FIRST;
}
void nextButton_Click(object sender, EventArgs e)
{
mainPanel.dispose();
}
void mainPanel_Disposed(object sender, EventArgs e)
{
if(currentScreen.Equals(screens.FIRST))
{
mainPanel = new secondPanel();
this.Controls.Add(mainPanel);
currentScreen = screens.SECOND;
}
}
}
Still looking for more input, links and examples are greatly appreciated.