Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I would like to get some code for closing a tab outside my form-the concept is that when I click close a dialogue comes up saying close all, or just this tab- I have sorted out close all, but not close tab- but I have some code for closing a tab inside the main form,

private void deleteTabToolStripMenuItem_Click(object sender, EventArgs e)
{
  // Close the current tab, unless it happens to be the last one
  if (current_tab_count < 2) return;

  TabPage current_tab = tabControl2.SelectedTab;
  WebBrowser thiswebpage = (WebBrowser)webpages[tabpages.IndexOf(current_tab)];
  tabpages.Remove(current_tab);            
  tabControl2.TabPages.Remove(current_tab);
  current_tab_count--;
}


I run C# 2010/.NET 4. So, could anyone help me? I've got a deadline.


I'm sorry, that's not what I'm looking for!
I want to be able to close a tab on my main form outside it- on a different form!

There will be a form- a new one that says close all or just this tab, i want to be able to make the just this tab button close just that tab that was open on a different form-I already have the code to delete a file, but need to know how to make it control a different form.
Posted
Updated 11-Dec-10 4:30am
v5
Comments
Abdul Quader Mamun 11-Dec-10 6:47am    
Use pre tag for better reading your code.
Toli Cuturicu 11-Dec-10 8:11am    
I deleted your fake answer this time.
Consider this a warning.
Never post fake answers again!

1 solution

I would do it something like this:

C#
if (tabControl2.TabPages.Count > 2 && tabControl2.SelectedTab != null)
{
    tabControl2.TabPages.Remove(tabControl2.SelectedTab);    
}


 
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