+ Reply to Thread
Results 1 to 2 of 2

Thread: Add buttons in tab control

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    15

    Add buttons in tab control

    I have a TabControl in a windows form. I have dynamically added new tabs like so:

    for (int i = 1; i < numOfLanguages; i++)
    {
    // add a tab for each language
    string tabTitle = split[i];
    TabPage newTab = new TabPage(tabTitle);
    languageTabs.TabPages.Add(newTab);
    }
    inside the loop I want to set up the other controlls for each tab. mainly I want to add buttons. I have seen this code:

    tabPage1.Controls.Add(new Button());
    Based off this example I want to do something similar like:

    languageTabs.SelectTab(split[i]).Add(new Button());
    I know that this code wont work. Have been looking through the params and cant see anything that lets me do this kind of thing.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    10
    SelectTab moves the actual TabControl to the specified tab, it does not return the tab to let you manipulate it.

    You can index into the tab pages as follows:

    languageTabs.TabPages[2].Controls.Add(new Button());
    If you have set the Name property on the TabPage on creation, then you can also find individual tabs by key:

    for (int i = 1; i < numOfLanguages; i++)
    {
    // add a tab for each language
    string tabTitle = split[i];
    TabPage newTab = new TabPage(tabTitle);
    newTab.Name = tabTitle;
    languageTabs.TabPages.Add(newTab);
    }

    languageTabs.TabPages[split[i]].Controls.Add(new Button());

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts