How can I duplicate tabPage in C #?

How can I duplicate "tabPage" inside my TabControl?

I tried this:

//My TabControl: tc //My Tab ID: 0 TabPage newPage = new TabPage(); foreach (Control control in tc.TabPages[0].Controls) { newPage.Controls.Add(control); } tc.TabPages.Add(newPage); 

but it does not work

Thank you in advance.

+6
source share
2 answers

I understood!

For those who have the same problem, here is what I did:

I created UserControl (thanks a lot for @SLaks and @Brian for your advice), copied all the objects from my TabControl into my new UserControl and used the following code to create dynamic tabs:

 for (int x = 0; x < 3; x++) { UserControl1 uc = new UserControl1(); TabPage tp = new TabPage(); tp.Controls.Add(uc); this.TabControl1.TabPages.Add(tp); } 
+12
source

As Shabs mentioned in the comment above, I highly recommend you do this with User Controls .

+1
source

Source: https://habr.com/ru/post/1488153/


All Articles