Skip to content

Create Tabbed MDI Interface

Lalit Kumar Barik

Asked Jul 16, 2009, 9:25 AM EDT2 answers
Share
LinkedInX
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.
Java
 

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

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi,

    Try the below code to add a form to a tab page.


    Form1 frm = new Form1();

    frm.TopLevel = false;
    frm.Visible = true;
    frm.FormBorderStyle = FormBorderStyle.None;
    frm.Dock = DockStyle.Fill;

    tabControl1.TabPages[0].Controls.Add(frm);


    Hope this helps.

    Cheers
    Dave
    0