Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Hide TabPages dynamicaly

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 679
    Answer it

    Hi..!
    I am working on Windows application using c#, in which I am using a TabControl. What I have to do is to open a tabpage dynamicaly on user's choice i.e if the user clicks on the NewUser button then the "New User" tabpage should get open & if the user clicks the Login button then the "Log In" tabpage should get open & the current tabpage should get close.

    I acheived this by using following methods:

    tabControl1.TabPages.Add(...)
    
    tabControl1.TabPages.Remove(...)
    

    But the problem is that when I remove the tabpages I am not able to get them back...! Please give some solution..? Thanks in advance !

 1 Answer(s)

  • Hi Mayank,
        The best solution I can suggest is that as you remove the TabPages from the Tab Control, keep the removed pages in the list so that you can get them later...

    Please go through the following example this will give you the exact idea I am talking about:

    private List<TabPage> removedPages = new List<TabPage>();
    
        private void EnablePage(TabPage page, bool enable) {
            if (enable) {
                tabControl1.TabPages.Add(page);
                removedPages.Remove(page);
            }
            else {
                tabControl1.TabPages.Remove(page);
                removedPages.Add(page);
            }
        }
    
        protected override void OnFormClosed(FormClosedEventArgs e) {
            foreach (var page in removedPages) page.Dispose();
            base.OnFormClosed(e);
        }
    
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: