I am making an application that requires tabs (tab-control) to be added or removed. I have done the add and remove for tabs fine, but I have custom buttons instead of using the tabs. (This button will go the the first tab page when clicked):
//This will make it go to TAB 1
private void button1_Click(object sender, EventArgs e)
{
tabControl1.SelectedIndex = 0;
}
//This will change the MOUSEENTER to the correct image
private void button1_MouseEnter(object sender, EventArgs e)
{
button1.MouseEnter += new EventHandler(button1_MouseEnter);
this.button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Tab_Down));
}
//This will change the MOUSELEAVE to the correct image
private void button1_MouseLeave(object sender, EventArgs e)
{
button1.MouseLeave += new EventHandler(button1_MouseLeave);
this.button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Tab_Norm));
}
However, how will I create it so when you click the "Add Tab" button it creates a new tab but it also creates a new button with tabControl1.SelectedIndex = 1;
in it for example.
Edit
I have done this to add a new tab (to tabControl1):
private void button2_Click(object sender, EventArgs e)
{
string title = "TabPage " + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);
}
This adds a new tab on top of the existing ones fine. But I how do I do it so that it also creates a new button with the properties of the button above but makes it so instead of tabControl1.SelectedIndex = 1;
it does tabControl1.SelectedIndex = 3;
and goes up every time I add a new tab? - Thanks