Bohn
Bohn

Reputation: 26919

Adding the same Panel to multiple TabPages

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.

Upvotes: 2

Views: 4514

Answers (1)

Fredrik Mörk
Fredrik Mörk

Reputation: 158309

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?

Upvotes: 7

Related Questions