public void RemoveTabHandler(object sender, EventArgs e) { ThemeTabControl tabcontrol = (ThemeTabControl)base.Component; if (tabcontrol == null || tabcontrol.TabPages.Count == 0) { return; } MemberDescriptor controlsdescriptor = TypeDescriptor.GetProperties(base.Component)["Controls"]; ThemeTab tab = tabcontrol.SelectedTab; IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (host == null) { return; } DesignerTransaction transaction = null; try { try { transaction = host.CreateTransaction("Remove Tab"); base.RaiseComponentChanging(controlsdescriptor); } catch (CheckoutException ex) { if (ex != CheckoutException.Canceled) { throw ex; } return; } host.DestroyComponent(tab); base.RaiseComponentChanged(controlsdescriptor, null, null); } finally { if (transaction != null) { transaction.Commit(); } } }
public void AddTabHandler(object sender, EventArgs e) { ThemeTabControl tabcontrol = (ThemeTabControl)this.Control; IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (host == null) { return; } DesignerTransaction transaction = null; try { try { transaction = host.CreateTransaction("Add Tab"); } catch (CheckoutException ex) { if (ex != CheckoutException.Canceled) { throw ex; } return; } MemberDescriptor controlsdescriptor = TypeDescriptor.GetProperties(tabcontrol)["Controls"]; ThemeTab tab = (ThemeTab)host.CreateComponent(typeof(ThemeTab)); base.RaiseComponentChanging(controlsdescriptor); string tabtext = null; PropertyDescriptor namedescriptor = TypeDescriptor.GetProperties(tab)["Name"]; if ((namedescriptor != null) && (namedescriptor.PropertyType == typeof(string))) { tabtext = (string)namedescriptor.GetValue(tab); } if (tabtext != null) { PropertyDescriptor textdescriptor = TypeDescriptor.GetProperties(tab)["Text"]; if (textdescriptor != null) { textdescriptor.SetValue(tab, tabtext); } } tabcontrol.Controls.Add(tab); tabcontrol.SelectedIndex = tabcontrol.TabPages.Count - 1; base.RaiseComponentChanged(controlsdescriptor, null, null); tabcontrol.tabbar.Invalidate(); } finally { if (transaction != null) { transaction.Commit(); } } }