Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# tabs
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 11-Dec-10 1:43am
hugheb186
Edited 11-Dec-10 5:30am
JF201553.3K
v5
Comments
Abdul Quader Mamun at 11-Dec-10 6:47am
   
Use pre tag for better reading your code.
Toli Cuturicu at 11-Dec-10 8:11am
   
I deleted your fake answer this time.
Consider this a warning.
Never post fake answers again!

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I would do it something like this:
 
if (tabControl2.TabPages.Count > 2 && tabControl2.SelectedTab != null)
{
    tabControl2.TabPages.Remove(tabControl2.SelectedTab);    
}


  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,569
1 Sergey Alexandrovich Kryukov 6,168
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 11 Dec 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100