Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I create multiple page in one windows Form without using Tab control in C#
Posted
Comments
ZurdoDev 29-Jul-13 9:38am    
What is a page on a form? It's just a screen so what do you mean by multiple pages? What do you want?
Ratnadip Kuri 29-Jul-13 11:13am    
Suppose, in main form i have a button,when we click the button then we will see a text or some thing on the same form where previous button is not present.now if i click Back button then we will go to previous page.
ZurdoDev 29-Jul-13 11:22am    
Just write code to do it. I am not sure, other than the tab control, of any control specifically designed to do that. As the solutions suggest, use some sort of grouping control and then just write the code to do it.

Create several panels with different content of each, make them all hidden, show one at a time.

—SA
 
Share this answer
 
You can use any container control like a GroupBox/Panel etc. and align each one to Top.
 
Share this answer
 
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!
C#
 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;
            //InitializeComponent();       
            
            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;
        }
 
Share this answer
 
v2
In WPF it is easy to create multiple page in one window where you have option of usercontrol.But in Windows I think you can use MDI parent class (or) create panel for each form and try to hide previous form but think it gets complicated since u'll write all logic in one page.
So,if possible use WPF where coding is similar to Winforms.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900