Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 396439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:33:09+00:00 2026-05-12T16:33:09+00:00

I want to remove a particular tabpage from the tabcontrol. For which i have

  • 0

I want to remove a particular tabpage from the tabcontrol. For which i have the value of tab name which has to be closed.

But, when i use..

for (int i = 0; i < myTabControl.TabPages.Count; i++)
{
    if (myTabControl.TabPages[i].Name.Equals(tabToRemove, StringComparison.OrdinalIgnoreCase))
    {
        myTabControl.TabPages.RemoveAt(i);
        break;
    }
}

It is not going inside the loop because the count is zero.
whereas the the tabcontrol is visible with two tabs in it.

whats the problem ?

This is how i am adding the tabs ->

public void TabIt(string strProcessName)
{
    this.Show();

    //Creating MDI child form and initialize its fields
    MDIChild childForm = new MDIChild();
    childForm.Text = strProcessName;
    childForm.MdiParent = this;

    //child Form will now hold a reference value to the tab control
    childForm.TabCtrl = tabControl1;

    //Add a Tabpage and enables it
    TabPage tp = new TabPage();

    tp.Parent = tabControl1;
    tp.Text = childForm.Text;
    tp.Show();
    //child Form will now hold a reference value to a tabpage
    childForm.TabPag = tp;
    //Activate the MDI child form
    childForm.Show();
    childCount++;

    //Activate the newly created Tabpage.
    tabControl1.SelectedTab = tp;
    tabControl1.ItemSize = new Size(200, 32);
    tp.Height = tp.Parent.Height;
    tp.Width = tp.Parent.Width;
}


public void GetTabNames()
{

    foreach (string strProcessName in Global.TabProcessNames)
    {
        TabIt(strProcessName);
    }
}

The child form :

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Diagnostics; using System.Drawing.Drawing2D;

namespace Daemon 
{ 

public class MDIChild : System.Windows.Forms.Form
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;
    private TabControl tabCtrl;
    private TabPage tabPag;

    public MDIChild()
    {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
    //MDIChild TargerForm = new MDIChild();
    //WinApi.SetWinFullScreen(TargerForm.Handle); 
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
            if( disposing )
            {
                    if(components != null)
                    {
                            components.Dispose();
                    }
            }
            base.Dispose( disposing );
    }

    public TabPage TabPag
    {
            get
            {
                    return tabPag;
            }
            set
            {
                    tabPag = value;
            }
    }

    public TabControl TabCtrl
    {
            set
            {
                    tabCtrl = value;
            }
    }


    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.SuspendLayout();
    // 
    // MDIChild
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    this.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
    this.ClientSize = new System.Drawing.Size(0, 0);
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
    this.MaximizeBox = false;
    this.MinimizeBox = false;
    this.Name = "MDIChild";
    this.Opacity = 0;
    this.ShowIcon = false;
    this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
    this.Text = "MDIChild"; 
    this.Activated += new System.EventHandler(this.MDIChild_Activated);
    this.Closing += new System.ComponentModel.CancelEventHandler(this.MDIChild_Closing);
    this.ResumeLayout(false);

    }
    #endregion

    private void MDIChild_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
    try
    {
        //Destroy the corresponding Tabpage when closing MDI child form
        this.tabPag.Dispose();

        //If no Tabpage left
        if (!tabCtrl.HasChildren)
        {
            tabCtrl.Visible = false;
        }
    }
    catch (Exception ex)
    { 
    }
    }

    private void MDIChild_Activated(object sender, System.EventArgs e)
    {
    try
    {
        //Activate the corresponding Tabpage
        tabCtrl.SelectedTab = tabPag;

        if (!tabCtrl.Visible)
        {
            tabCtrl.Visible = true;
        }
        Global.ExistingTabProcessNames.Add(tabPag.Text);
    }
    catch (Exception ex)
    { 
    }
    }
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T16:33:09+00:00Added an answer on May 12, 2026 at 4:33 pm

    If you have the name of the TabPage what is wrong with doing just this…

    tabControl1.TabPages.RemoveByKey("tabPage1");
    

    ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a tabcontrol, i want to remove a particular tab from the
I have a bunch of java files from which I want to remove the
I have an ArrayList<String> , and I want to remove repeated strings from it.
I want to use the Publish.GacRemove function to remove an assembly from GAC. However,
How can i remove the tabs from tabcontrol when i reference each tab to
I want to remove a particular substring from all the file names in a
i want to remove a particular #keyword from a string. i dont know its
I want to remove classes in the particular div. I mean i have to
I want remove "Language" querystring from my url. How can I do this? (using
I want to remove a UIView from a superview and add it again at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.