I am using C# 2005 to create a Windows application. I have a MDIForm (frmMainMenu) which contains a Menustrip and a
TabControl. My ChildForm is frmPurchaseEntry. When the user clicks on a particular Menu option a new TabPage is created and
the child form is displayed within the TabPage.
I am using the following code in the MenuClick event of the MDIForm (frmMainMenu) :
frmPurchaseEntry PurchaseEntry = new frmPurchaseEntry(); PurchaseEntry.MdiParent = this; PurchaseEntry.TabCtrl = tabControl1; PurchaseEntry.TopLevel = false; PurchaseEntry.Visible = true; PurchaseEntry.FormBorderStyle = FormBorderStyle.None; PurchaseEntry.Dock = DockStyle.Fill; TabPage tpPurchaseEntry = new TabPage(); tpPurchaseEntry.Parent = tabControl1; tpPurchaseEntry.Text = PurchaseEntry.Text; tpPurchaseEntry.Controls.Add(PurchaseEntry); tpPurchaseEntry.Show(); PurchaseEntry.Select(); tabControl1.SelectedTab = tpPurchaseEntry ;
Everything is OK upto this. But I am unable to remove the TabPage when the ChildForm is closed. The following command only
closes the ChildForm, but the empty TabPage still remains.
I know the syntax to remove a TabPage is
But Im unable to access the TabControl of MDIForm from the ChildForm. I tried to use Public modifier for the TabControl, but still it is not exposed from the ChildForm.
How can I remove AND dispose a particular TabPage (with a particular Tab Text) from the ChildForm???
Lalit Kumar Barik