Copy TabControl Tab

后端 未结 3 434
别那么骄傲
别那么骄傲 2020-12-10 16:21

I searched the internet for this but i couldn\'t find how to do it with C#

What i am trying to do is make it so that when i click on my NewTab button, a

3条回答
  •  [愿得一人]
    2020-12-10 16:54

    I know it's an old thread but I just figured out a way for myself and thought I should share it. It's really simple and tested in .Net 4.6.

    Please note that this solution does not actually create new controls, just re-assigns them all to new TabPage, so you have to use AddRange each time you change tabs. New tab will show the exact same controls, content and values included.

    // Create an array and copy controls from first tab to it.
    Array tabLayout = new Control [numberOfControls];
    YourTabControl.TabPages[0].Controls.CopyTo(tabLayout, 0);
    
    // AddRange each time you change a tab.
    YourTabControl.TabPages[newTabIndex].Controls.AddRange((Control[])tabLayout);
    

提交回复
热议问题