0

I am a C# learner. In Windows Forms App, I want to remove some of TabPages temporarily. So I made this code with refered to web sites.

    public class GetTabPageInfo
    {
        private class TabPageInfo
        {
            public TabPage TabPage;
            public TabPageInfo(TabPage page)
            {
                TabPage = page;
            }
        }

        private TabPageInfo[] tabPageInfos = null;

        public GetTabPageInfo(TabControl tabCrl)
        {
            tabPageInfos = new TabPageInfo[tabCrl.TabPages.Count];

            for (int i = 0; i < tabCrl.TabPages.Count; i++)
            {
                tabPageInfos[i] = new TabPageInfo(tabCrl.TabPages[i]);
            }
        }
    }

And I could tabpages except the first tab by this code.

    private void testButton_Click(object sender, EventArgs e)
    {
        tabPages = new GetTabPageInfo(tabControl);

        int tabs = tabControl.TabCount;
        for (int i = tabs - 1; 0 < i; i--)
        {
            if (0 < i)
                tabControl.TabPages.RemoveAt(i);
        }
    }

But, I can't keep the tabPageInfos in a variable out side this code. So, I can't add those removed tab again.

Would you tell me how to get tabPageInfos? And how to add those tabPages?

FaceTowel
  • 19
  • 6
  • Every `TabPage` created in the designer are accessible by variable generated in the form designer code. So you can use `TabControl.TabPages.Remove(this.TabPageControl1)` – Fabio Feb 07 '16 at 10:24
  • I can't accept your answer so I want to have how to get the information of those tabpages, and then add again. I don't want only to remove tabpages, but I want to get the all of the informations of those tabs. – FaceTowel Feb 07 '16 at 10:44
  • I can remove tabpages, you know? – FaceTowel Feb 07 '16 at 10:53
  • `this.TabPageControl1` is a instanse of TabPage you need. This contains all information you want and you can add it again: `TabControl.TabPages.Add(this.TabPageControl1)` – Fabio Feb 07 '16 at 12:14
  • >Every TabPage created in the designer are accessible by variable generated in the form designer code ----> Thanks! I'm going to try it. – FaceTowel Feb 08 '16 at 03:09

0 Answers0