tabcontrol

hi,

how can i hide a tabpage2 in a tabcontrol when the form is loaded , and how can i show it again when the user click a button in the first tabpage if that is possible




Answer this question

tabcontrol

  • osj

    thx guys

    its working now pretty good

    best regards



  • j42

    It should keep its controls. I did this a while ago and it worked.


  • Terry Showers

    hi,

    that's great but how can i remove a tabpage and add it again programaticly

    thx in advance



  • yashpal singh

    hi,

    thx for the answer but the tabcontrol contain some controls if adding it back to the collection will not remove the controls so how can i remove it or add it again



  • Codeurai

    First you need to add a field to your class to remember the removed tab page:

    class YourForm : Form

    {

    ... some other code

    private TabPage savedTabPage;

    ...

    }

    then when you need to hide the TabPage, let's say in Load event:

    void YourForm_Load(...)

    {

    // you said you want to remove the second page, so

    savedTabPage = tabControl.TabPages[1];

    tabControl.TabPages.RemoveAt(1);

    ...

    }

    and when you want to show the tab page, let's say in someButton_Click event:

    void someButton_Click(object sender, EventArgs e)

    {

    // let's check if we need to add the page

    if (savedTabPage != null)

    {

    tabControl.TabPages.Add(savedTabPage);

    // let's make sure we don't add the page a second time

    // withour removing it first

    saveTabPage = null;

    }

    }

    Still... maybe you should reconsider the interface a bit... adding a tab page when the user presses a button may confuse the user.


  • SMB

    See the methods on my Tabcontrol tips page:

    http://www.dotnetrix.co.uk/tabcontrols.html


  • Gautam Goenka

    You can remove the tabpage from the TabPages collection of the TabControl, keep a reference to it in your class and add it back to TabPages when you need it.
  • tabcontrol