简体   繁体   中英

Add tabcontrol to dynamically created tab control in winforms

I've a tabcontrol on my page with 2 tabs. Now I want to create another tabcontrol dynamically and want to add the existing tab control to dynamically created tab control tabs.

Is is possible? I'm not able to add this.

Here is my code:

       TabControl tbdynamic = new TabControl();
       TabPage tbpaagedynamic = new TabPage();
       tbpaagedynamic.Controls.Add(statictabcontrol);
       tbdynamic.TabPages.Add(tbpaagedynamic);

Any idea?

Yes, it is posiible. Add dynamic tab to Form :

this.Controls.Add(tbdynamic);

example

TabControl tbdynamic = new TabControl();
tbdynamic.Height = 200;
tbdynamic.Width = 200;
TabPage mPage = new TabPage();
mPage.Text = "Test Page";
tbdynamic.TabPages.Add(mPage);

mPage.Controls.Add(statictabcontrol);

statictabcontrol.Top = 0;
statictabcontrol.Left = 0;
this.Controls.Add(tbdynamic);

Just add the bringToFrontMethod() at the end of adding it to your Window.

tbdynamic.BringToFRont();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM