Search code examples
c#user-controlsdynamic-controls

create dynamic tabs and use control of tabs in C#.net


I created one emulator for one device, so each time the user clicks on the button I am creating one new form, and each form represents new devices.

now I am looking for another option by which inside my main form I can create multiple tabs (instead of multiple forms) which has controls like button, dropdown, text box, grid view. and the user can navigate between tabs, create a new tab dynamically, use controls inside of the tab.

any suggestion ??

enter image description here


Solution

  • Just use the TabControl on my 'main form'. and added tab pages at runtime.

    tabControl1.TabPages.Add("New Tab");
    

    placed an entire form inside a tab control ...this code will create a new instance of a form and place it in the last tab of a tab control:

    frmDevice dev = new frmDevice();
    dev.TopLevel = false;
    dev.FormBorderStyle = FormBorderStyle.None;
    dev.Parent = tabControl1.TabPages[tabControl1.TabCount - 1];
    dev.Dock = DockStyle.Fill;
    dev.Show();
    

    Reference :https://www.codeproject.com/Answers/5246227/Create-dynamic-tabs-and-use-control-of-tabs-in-csh#answer1