Here is a very fast code that I wrote for you. One possible way is:
- put two panels to your form. One is header which is docked to top and one main header which docked fill.
- add a label, a textbox and a button to the top header for selecting any page number that you want and press button to select the page.
- add any number of panels that you want to the main panel and make them all invisible. store each panel object with a number indicating its page_num in a dictionary.
- put any page contents that you have in your panels.
- handle button click event and make any page number that has the same number as the textbox value visible.
- enjoy!
Dictionary<int,> pageNumberToPanel = new Dictionary<int,>();
Button buttonChangePage = new Button();
TextBox pageNumText = new TextBox();
Panel main = new Panel();
Panel topHeader = new Panel();
Label label = new Label();
public FormMain()
{
int pageCount = 3;
main.Size = new Size(this.Width, this.Height - 30);
main.Dock = DockStyle.Fill;
topHeader.Size = new Size(this.Width, 30);
topHeader.Dock = DockStyle.Top;
for (int i = 0; i < pageCount; i++)
CreatePanel(i, main);
buttonChangePage.Text = "Change Page";
buttonChangePage.Parent = topHeader;
buttonChangePage.Dock = DockStyle.Left;
buttonChangePage.Click +=
delegate(object sender, EventArgs args)
{
for (int i = 0; i < pageNumberToPanel.Count; i++)
{
if (i == int.Parse(pageNumText.Text))
pageNumberToPanel[i].Visible = true;
else
pageNumberToPanel[i].Visible = false;
}
};
pageNumText.Parent = topHeader;
pageNumText.Text = "0";
pageNumText.Dock = DockStyle.Left;
label.Parent = topHeader;
label.Text = "Page Number: ";
label.Dock = DockStyle.Left;
main.Parent = this;
topHeader.Parent = this;
}
public void CreatePanel(int panelNum, Panel parentPanel)
{
Panel p = new Panel();
p.Dock = DockStyle.Fill;
Label t = new Label();
t.Text = string.Format("Page {0}", panelNum);
t.Parent = p;
t.Dock = DockStyle.Fill;
p.Parent = parentPanel;
pageNumberToPanel.Add(panelNum, p);
p.Visible = false;
}