/// <summary> /// Allows to add new task control /// </summary> /// <param name="id">task ID</param> /// <param name="tabControl">TabControl to add to</param> private void AddUserControl(TabControl tabControl, long id = -1) { try { tabControl.SelectTab( tabControl.TabPages .Cast<TabPage>() .First(x => x.Tag != null && x.Tag.ToString() == id.ToString(CultureInfo.InvariantCulture))); } catch (Exception) { var tp = new TabPage {Tag = id}; var tuc = new TaskUserControl(this, id) {Dock = DockStyle.Fill}; tuc.TaskOpened += AddUserControl; tuc.TaskClosed += TucTaskClosed; tp.Controls.Add(tuc); tabControl.TabPages.Add(tp); tabControl.SelectTab(tp); } }
/// <summary> /// Event of task closed /// </summary> /// <param name="uc">TaskUserControl</param> private void TucTaskClosed(TaskUserControl uc) { Populate(); GetTabControl.TabPages.Remove((TabPage) uc.Parent); }