Controls on tab pages

Hi,

I have a tab control and several tab pages within it. I have a set a controls like buttons, textboxes etc... that I want to appear on each of the tab pages. I want the same set of controls to appear on each of the tab pages. I will update their values on the tab control's SelectedIndexChanged event.

How do I get that one set of controls to appear on each tab page

Thanks


Answer this question

Controls on tab pages

  • castrini

    Cool. I went with the AddRange()/Clear() solution.

    Thanks

  • Pawel Pabich

    Say you have 8 blank tab pages with the titles of your tabs.  Then you have a single populated tab page that isn't visible.  Whenever your selected index is changed to a new tab, you update the populated tab page's Text property with that of the selected tab, hide the selected tab, and allow the fully populated pseudo tab to take it's place.  In this manner you really only have one tab that is simulating many tabs.

    There are better ways to do this that provide a better closure and cleaner code, but you should be able to get away with quickly coding this.

  • Karlo123

    All controls have a parent control.  They can only exist on one parent at any given point in time.  You could use AddRange to move the controls around to the various tab pages as they are switched, but they can't exist on more than one TabPage at any given time.
  • vaidya

    Thanks for your response.

    Tab Pages have a control collection of all the controls "embedded" within them right  As in tabPage1.Controls.AddRange( new Control[] { button1, button2 } ); 

    Well, I tried to have a common Control array of all the controls and add that array to the tab pages...

    Control[] controls = new Control[] { button1, button2 } );

    And then

    tabPage1.Controls.AddRange( controls );
    tabPage2.Controls.AddRange( controls );

    But that didn't seem to work. Only the tabPage2 would have the controls on it. Any idea why this is happening

    Regarding your solution. How would I get the hidden tabPage to appear in the position of the one that was clicked

    Thanks again.

  • Controls on tab pages