views:

86

answers:

1

In my previous question I could add a design time panel to a tab page at run time and my code looks like this and it works Ok.

        tabControl1.SuspendLayout();
        tabControl1.TabPages[0].Controls.Add(panel1);
        tabControl1.ResumeLayout();

but now I need to do something like this:

    tabControl1.SuspendLayout();
    tabControl1.TabPages[0].Controls.Add(panel1);
    tabControl1.TabPages[1].Controls.Add(panel1);
    tabControl1.TabPages[2].Controls.Add(panel1);
    tabControl1.ResumeLayout();

which just at run-time I can know how many of these Tabpages I will need. but now for testing I am assuming I will have three tabPages

the Problem is that the panel only gets added to the Last tabPage, How can I fix this? I want it get added to all of the tab pages Thanks.

+1  A: 

You can't. A control can have only one parent at a time. Luckily, only one tab page is visible at a time, so I guess you could move the panel between the pages as they are displayed? On the other hand, if the panel is to be located in the same place for all pages, perhaps it should not be placed inside the tab control, but rather on top of it?

Fredrik Mörk
Ok Thanks, so I guess I should do this: Parent of Panel should be TabPage[0] AT FIRST because the at least I will have one page and th user will see it at first. ...but on the event of TabPageChange I should change the Parent of that Panel to be TabPage[currentTabIndex] Is that Ok?
BDotA
@BDotA: I *think* that should work. I would give it a shot and see how it works out.
Fredrik Mörk