Multiple Pages on same form

J

John Carnahan

What is the best way to simulate multiple pages on the same form?
For example:

Similar to a tab page, but I want to be able to put different UI objects on
each page and walk the user through a series of pages.
i.e. page 1...page 2..page3 etc.
I know how to do it with separate forms, but I would like only one form if
possible.
The panel can be controlled with the visible property to simulate this at
runtime, but not at design time.
The tab control acts great at design time, but doesn't appear to have the
paging control at runtime. (i.e. tab1.visible)
Is there some other way to do this?
 
G

Guest

As Far as I know you have add and remove them.

As Follows.

using System
using System.Drawing
using System.Collections
using System.ComponentModel
using System.Windows.Forms
using System.Data

namespace TabControlpage

/// <summary
/// Summary description for Form1
/// </summary
public class Form1 : System.Windows.Forms.For

private ArrayList pages = new ArrayList()
private int currentPage = 0
private System.Windows.Forms.Panel panel1
private System.Windows.Forms.Button previousButton
private System.Windows.Forms.Button nextButton
private System.Windows.Forms.TabControl tabControl1
private System.Windows.Forms.TabPage tabPage10
private System.Windows.Forms.TabPage tabPage11
private System.Windows.Forms.TabPage tabPage12
private System.Windows.Forms.TabPage tabPage13
/// <summary
/// Required designer variable
/// </summary
private System.ComponentModel.Container components = null

public Form1(

/
// Required for Windows Form Designer suppor
/
InitializeComponent()

this.pages.AddRange(tabControl1.TabPages)
this.currentPage = 0
tabControl1.TabPages.Clear()
tabControl1.TabPages.Add( (TabPage)pages[currentPage])
SetButtons()


private void previousButton_Click(object sender, System.EventArgs e

if (currentPage > 0) currentPage --
tabControl1.TabPages.Clear()
tabControl1.TabPages.Add((TabPage)pages[currentPage])
SetButtons()


private void nextButton_Click(object sender, System.EventArgs e

if (currentPage < pages.Count - 1 ) currentPage ++
tabControl1.TabPages.Clear()
tabControl1.TabPages.Add((TabPage)pages[currentPage])
SetButtons()

private void SetButtons(

if (currentPage <= 0) previousButton.Enabled = false
else previousButton.Enabled = true
if (currentPage < pages.Count -1 ) nextButton.Enabled = true
else nextButton.Enabled = false


/// <summary
/// Clean up any resources being used
/// </summary
protected override void Dispose( bool disposing

if( disposing

if (components != null)

components.Dispose()


base.Dispose( disposing )


#region Windows Form Designer generated cod
/// <summary
/// Required method for Designer support - do not modif
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(

this.panel1 = new System.Windows.Forms.Panel()
this.previousButton = new System.Windows.Forms.Button()
this.nextButton = new System.Windows.Forms.Button()
this.tabControl1 = new System.Windows.Forms.TabControl()
this.tabPage10 = new System.Windows.Forms.TabPage()
this.tabPage11 = new System.Windows.Forms.TabPage()
this.tabPage12 = new System.Windows.Forms.TabPage()
this.tabPage13 = new System.Windows.Forms.TabPage()
this.panel1.SuspendLayout()
this.tabControl1.SuspendLayout()
this.SuspendLayout()
//
// panel
//
this.panel1.Controls.Add(this.nextButton)
this.panel1.Controls.Add(this.previousButton)
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom
this.panel1.Location = new System.Drawing.Point(0, 218)
this.panel1.Name = "panel1"
this.panel1.Size = new System.Drawing.Size(292, 48)
this.panel1.TabIndex = 1
//
// previousButto
//
this.previousButton.Location = new System.Drawing.Point(56, 8)
this.previousButton.Name = "previousButton"
this.previousButton.TabIndex = 0
this.previousButton.Text = "Last"
this.previousButton.Click += new System.EventHandler(this.previousButton_Click)
//
// nextButto
//
this.nextButton.Location = new System.Drawing.Point(144, 8)
this.nextButton.Name = "nextButton"
this.nextButton.TabIndex = 1
this.nextButton.Text = "Next"
this.nextButton.Click += new System.EventHandler(this.nextButton_Click)
//
// tabControl
//
this.tabControl1.Controls.Add(this.tabPage10)
this.tabControl1.Controls.Add(this.tabPage11)
this.tabControl1.Controls.Add(this.tabPage12)
this.tabControl1.Controls.Add(this.tabPage13)
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill
this.tabControl1.ItemSize = new System.Drawing.Size(58, 18)
this.tabControl1.Location = new System.Drawing.Point(0, 0)
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(292, 266);
this.tabControl1.TabIndex = 0;
//
// tabPage10
//
this.tabPage10.Location = new System.Drawing.Point(4, 22);
this.tabPage10.Name = "tabPage10";
this.tabPage10.Size = new System.Drawing.Size(284, 240);
this.tabPage10.TabIndex = 0;
this.tabPage10.Text = "tabPage10";
//
// tabPage11
//
this.tabPage11.Location = new System.Drawing.Point(4, 22);
this.tabPage11.Name = "tabPage11";
this.tabPage11.Size = new System.Drawing.Size(284, 240);
this.tabPage11.TabIndex = 1;
this.tabPage11.Text = "tabPage11";
//
// tabPage12
//
this.tabPage12.Location = new System.Drawing.Point(4, 22);
this.tabPage12.Name = "tabPage12";
this.tabPage12.Size = new System.Drawing.Size(284, 240);
this.tabPage12.TabIndex = 2;
this.tabPage12.Text = "tabPage12";
//
// tabPage13
//
this.tabPage13.Location = new System.Drawing.Point(4, 22);
this.tabPage13.Name = "tabPage13";
this.tabPage13.Size = new System.Drawing.Size(284, 240);
this.tabPage13.TabIndex = 3;
this.tabPage13.Text = "tabPage13";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.panel1);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

}
}
 
J

John Carnahan

Thanks , that helps
John

Mike in Paradise said:
As Far as I know you have add and remove them..

As Follows..

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TabControlpages
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private ArrayList pages = new ArrayList();
private int currentPage = 0;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button previousButton;
private System.Windows.Forms.Button nextButton;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage10;
private System.Windows.Forms.TabPage tabPage11;
private System.Windows.Forms.TabPage tabPage12;
private System.Windows.Forms.TabPage tabPage13;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

this.pages.AddRange(tabControl1.TabPages);
this.currentPage = 0;
tabControl1.TabPages.Clear();
tabControl1.TabPages.Add( (TabPage)pages[currentPage]);
SetButtons();
}

private void previousButton_Click(object sender, System.EventArgs e)
{
if (currentPage > 0) currentPage --;
tabControl1.TabPages.Clear();
tabControl1.TabPages.Add((TabPage)pages[currentPage]);
SetButtons();
}

private void nextButton_Click(object sender, System.EventArgs e)
{
if (currentPage < pages.Count - 1 ) currentPage ++;
tabControl1.TabPages.Clear();
tabControl1.TabPages.Add((TabPage)pages[currentPage]);
SetButtons();
}
private void SetButtons()
{
if (currentPage <= 0) previousButton.Enabled = false;
else previousButton.Enabled = true;
if (currentPage < pages.Count -1 ) nextButton.Enabled = true;
else nextButton.Enabled = false;
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.previousButton = new System.Windows.Forms.Button();
this.nextButton = new System.Windows.Forms.Button();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage10 = new System.Windows.Forms.TabPage();
this.tabPage11 = new System.Windows.Forms.TabPage();
this.tabPage12 = new System.Windows.Forms.TabPage();
this.tabPage13 = new System.Windows.Forms.TabPage();
this.panel1.SuspendLayout();
this.tabControl1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.Add(this.nextButton);
this.panel1.Controls.Add(this.previousButton);
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel1.Location = new System.Drawing.Point(0, 218);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(292, 48);
this.panel1.TabIndex = 1;
//
// previousButton
//
this.previousButton.Location = new System.Drawing.Point(56, 8);
this.previousButton.Name = "previousButton";
this.previousButton.TabIndex = 0;
this.previousButton.Text = "Last";
this.previousButton.Click += new System.EventHandler(this.previousButton_Click);
//
// nextButton
//
this.nextButton.Location = new System.Drawing.Point(144, 8);
this.nextButton.Name = "nextButton";
this.nextButton.TabIndex = 1;
this.nextButton.Text = "Next";
this.nextButton.Click += new System.EventHandler(this.nextButton_Click);
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage10);
this.tabControl1.Controls.Add(this.tabPage11);
this.tabControl1.Controls.Add(this.tabPage12);
this.tabControl1.Controls.Add(this.tabPage13);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.ItemSize = new System.Drawing.Size(58, 18);
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(292, 266);
this.tabControl1.TabIndex = 0;
//
// tabPage10
//
this.tabPage10.Location = new System.Drawing.Point(4, 22);
this.tabPage10.Name = "tabPage10";
this.tabPage10.Size = new System.Drawing.Size(284, 240);
this.tabPage10.TabIndex = 0;
this.tabPage10.Text = "tabPage10";
//
// tabPage11
//
this.tabPage11.Location = new System.Drawing.Point(4, 22);
this.tabPage11.Name = "tabPage11";
this.tabPage11.Size = new System.Drawing.Size(284, 240);
this.tabPage11.TabIndex = 1;
this.tabPage11.Text = "tabPage11";
//
// tabPage12
//
this.tabPage12.Location = new System.Drawing.Point(4, 22);
this.tabPage12.Name = "tabPage12";
this.tabPage12.Size = new System.Drawing.Size(284, 240);
this.tabPage12.TabIndex = 2;
this.tabPage12.Text = "tabPage12";
//
// tabPage13
//
this.tabPage13.Location = new System.Drawing.Point(4, 22);
this.tabPage13.Name = "tabPage13";
this.tabPage13.Size = new System.Drawing.Size(284, 240);
this.tabPage13.TabIndex = 3;
this.tabPage13.Text = "tabPage13";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.panel1);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top