Skip to content

Remove a TabPage

Lalit Kumar Barik

Asked Jul 21, 2009, 2:21 AM EDT1 answer
Share
LinkedInX
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) :
Java
 


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.
Code
 this.Close();

I know the syntax to remove a TabPage is
Code
 tabControl1.TabPages.Remove(tabControl1.SelectedTab);

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???
Thank you.
Lalit Kumar Barik

1 Answer

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

  • 0
    Cross posted: http://www.daniweb.com/forums/thread205588.html
    0