I am using C# 2005 to develop an Windows application. I am planning to use a Tab Container to display the child forms. I have used a Menu Strip to display the menu and have set IsMDIContainer = true property of the MainMenu form. The MainMenu form also contains a Tab Control and I plan to display all child forms as Tap Pages in the Tab Control.

Till now I have been able to add Tab Pages when the user chooses a menu option. But I don't know how to display the child form itself within the Tab Page.

I have used the following code in the menu click event.

frmPurchaseEntry PurchaseEntry = new frmPurchaseEntry;
PurchaseEntry.MdiParent = this;
PurchaseEntry.TabCtrl = tabControl1;

TabPage tpPurchaseEntry = new TabPage();
 tpPurchaseEntry.Parent = tabControl1;

 tpPurchaseEntry.Text = "Purchase Entry";
 tpPurchaseEntry.Show();

PurchaseEntry.TabPag = tpPurchaseEntry;
PurchaseEntry.Show();
tabControl1.SelectedTab = tpPurchaseEntry;

How can I display the child form properly in the Tab Page?? I don't want a File -> New type of application, where menu click event displays the same (blank) form. My menu options should each display a unique/distinct form.

Thank You.

Lalit Kumar Barik

Recommended Answers

All 2 Replies

Hello, as far as I understand - the tab pages and child forms are created in the runtime. So probably the solution can be something like this:

TabPage tabPage1 = new TabPage("ChildForm1");

            //you can use or pre-defined class for this, or just 
            //call upon Form class
            YourFormClass childForm1 = new YourFormClass();
            childForm1.TopLevel = false;
            childForm1.Visible = true;   

            //Also Anchor and Dock properties are the playground for
            //you to find the best arrangement       
            childForm1.Anchor = AnchorStyles.Bottom & AnchorStyles.Left & AnchorStyles.Right & AnchorStyles.Top;
            childForm1.Dock = DockStyle.Fill;
            childForm1.FormBorderStyle = FormBorderStyle.None;
            tabPage1.Controls.Add(childForm1);
            tabControl1.TabPages.Add(tabPage1);

Antenka
ID CORRECT I THINK

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.