117-c-sharp-tab-control

C sharp tab control is control from TabControl Class. C sharp tab control is the part of C# Containers Toolbox.

c-sharp-tab-control-in-container

Once when it is added to Windows form, additional tabs can be added as collection.

tab-control-pages

We can add two more command buttons to form, one for adding tabs on click, and another for removing tabs on click.

Corresponding code is:
int int_how_many_tabs = 2;
private void btnAdd_Click(object sender, EventArgs e)
{

string str_title = “New Tab” + (++int_how_many_tabs).ToString();
TabPage myTabPage = new TabPage(str_title);
tabControl1.TabPages.Add(myTabPage);

}

private void btnRemove_Click(object sender, EventArgs e)
{

try
{

tabControl1.TabPages.Remove(tabControl1.SelectedTab);

}
catch
{

MessageBox.Show(“No more tabs”,”Tabs”,MessageBoxButtons.OK,MessageBoxIcon.Stop);

}

}
All tabs can be counted and their number can be converted to string by
string str_title = “New Tab” + tabControl1.TabCount.ToString();

note: Access to TabControl TabPages is similar to access of ListBox Items (SelectedTab <=> SelectedIndex).

External links:

C Sharp Tab Control on C-Sharpcorner
C Sharp Tab Control on Microsoft
C Sharp Tab Control on Yevol

Posted in c-sharp-code-examples

Leave a Reply

Your email address will not be published. Required fields are marked *

*