This is based on the idea that you should only create a new object (TabPage) when you require one:
private void button_New_Click(object sender, EventArgs e)
{
foreach (TabPage tp in tabControl.TabPages)
{
if (tp.Tag != null && tp.Tag.Equals(tpEmployee.Tag))
{
tabControl.SelectedTab = tp;
tp.Focus();
return;
}
}
TabPage tpEmployee = new TabPage(emp.Vorname);
tpEmployee.Tag = emp.ID;
GUI.Ucemp ucempTes = new GUI.UCemp();
Ucemptest.Employee = emp;
Ucemptest.Dock = DockStyle.Fill;
tpEmployee.Controls.Add(ucempTes);
}
If you can get a reference to the 'ucempTes inside the TabPage, and you want to set force Focus to a Control inside the 'ucempTes, like a TextBox:
tp.Controls["ucempTes"].Controls["textBox1"].Focus();
tp.Controls["ucempTes"].Controls["textBox1"].Capture = true;
This tedious repetition of dot-notation access can be eliminated by creating a Dictionary mapping the object you wish to focus on in each TabPage to the DataGridView rows.