Procedura: aggiungere e rimuovere schede tramite il controllo TabControl Windows Form

Per impostazione predefinita, un TabControl controllo contiene due TabPage controlli. È possibile accedere a queste schede tramite la TabPages proprietà .

Per aggiungere una scheda a livello di codice

  • Utilizzare il Add metodo della TabPages proprietà .

    Dim myTabPage As New TabPage()  
    myTabPage.Text = "TabPage" & (TabControl1.TabPages.Count + 1)  
    TabControl1.TabPages.Add(myTabPage)  
    
    string title = "TabPage " + (tabControl1.TabCount + 1).ToString();  
    TabPage myTabPage = new TabPage(title);  
    tabControl1.TabPages.Add(myTabPage);  
    
    String^ title = String::Concat("TabPage ",  
       (tabControl1->TabCount + 1).ToString());  
    TabPage^ myTabPage = gcnew TabPage(title);  
    tabControl1->TabPages->Add(myTabPage);  
    

Per rimuovere una scheda a livello di codice

  • Per rimuovere le schede selezionate, utilizzare il Remove metodo della TabPages proprietà .

    -oppure-

  • Per rimuovere tutte le schede, utilizzare il Clear metodo della TabPages proprietà .

    ' Removes the selected tab:  
    TabControl1.TabPages.Remove(TabControl1.SelectedTab)  
    ' Removes all the tabs:  
    TabControl1.TabPages.Clear()  
    
    // Removes the selected tab:  
    tabControl1.TabPages.Remove(tabControl1.SelectedTab);  
    // Removes all the tabs:  
    tabControl1.TabPages.Clear();  
    
    // Removes the selected tab:  
    tabControl1->TabPages->Remove(tabControl1->SelectedTab);  
    // Removes all the tabs:  
    tabControl1->TabPages->Clear();  
    

Vedi anche