Click here to Skip to main content
11,922,641 members (56,905 online)
Rate this:
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)];

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
Edited 11-Dec-10 5:30am
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

Rate this: bad
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)


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151125.1 | Last Updated 11 Dec 2010
Copyright © CodeProject, 1999-2015
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