private void OnComponentChanged(object sender, ComponentChangedEventArgs e) { MetroSetTabControl parentControl = e.Component as MetroSetTabControl; if (parentControl != null && e.Member.Name == "TabPages") { foreach (DesignerVerb verb in Verbs) { if (verb.Text == "Remove Tab") { switch (parentControl.TabPages.Count) { case 0: verb.Enabled = false; break; default: verb.Enabled = true; break; } break; } } } }
/* When the designer modifies the MetroSetTabControl.TabPages collection, * the Properties window is not updated until the control is deselected and then reselected. To * correct this defect, you need to explicitly notify the IDE that a change has been made by using * the PropertyDescriptor for the property. */ private void OnAddTab(Object sender, EventArgs e) { MetroSetTabControl parentControl = Control as MetroSetTabControl; TabControl.TabPageCollection oldTabs = parentControl.TabPages; // Notify the IDE that the TabPages collection property of the current tab control has changed. RaiseComponentChanging(TypeDescriptor.GetProperties(parentControl)["TabPages"]); MetroSetTabPage newTab = (MetroSetTabPage)_designerHost.CreateComponent(typeof(MetroSetTabPage)); newTab.Text = newTab.Name; parentControl.TabPages.Add(newTab); parentControl.SelectedTab = newTab; RaiseComponentChanged(TypeDescriptor.GetProperties(parentControl)["TabPages"], oldTabs, parentControl.TabPages); }
private void OnRemoveTab(Object sender, EventArgs e) { MetroSetTabControl parentControl = Control as MetroSetTabControl; if (parentControl.SelectedIndex < 0) { return; } TabControl.TabPageCollection oldTabs = parentControl.TabPages; // Notify the IDE that the TabPages collection property of the current tab control has changed. RaiseComponentChanging(TypeDescriptor.GetProperties(parentControl)["TabPages"]); _designerHost.DestroyComponent(parentControl.SelectedTab); RaiseComponentChanged(TypeDescriptor.GetProperties(parentControl)["TabPages"], oldTabs, parentControl.TabPages); }