private void OnComponentRemoving(object sender, ComponentEventArgs e) { // If our control is being removed if (e.Component == _ribbon) { // Need access to host in order to delete a component IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); // We need to remove all the button spec instances for (int i = _ribbon.ButtonSpecs.Count - 1; i >= 0; i--) { ButtonSpec spec = _ribbon.ButtonSpecs[i]; _ribbon.ButtonSpecs.Remove(spec); host.DestroyComponent(spec); } // We need to remove all the QAT button specifications for (int i = _ribbon.QATButtons.Count - 1; i >= 0; i--) { Component button = _ribbon.QATButtons[i]; _ribbon.QATButtons.Remove(button); host.DestroyComponent(button); } // We need to remove all the ribbon context instances for (int i = _ribbon.RibbonContexts.Count - 1; i >= 0; i--) { KryptonRibbonContext context = _ribbon.RibbonContexts[i]; _ribbon.RibbonContexts.Remove(context); host.DestroyComponent(context); } // We need to remove all the ribbon tab instances for (int i = _ribbon.RibbonTabs.Count - 1; i >= 0; i--) { KryptonRibbonTab tab = _ribbon.RibbonTabs[i]; _ribbon.RibbonTabs.Remove(tab); host.DestroyComponent(tab); } } }
private Color CheckForContextColor(PaletteState state) { // We need an associated ribbon tab if (_ribbonTab != null) { // Does the ribbon tab have a context setting? if (!string.IsNullOrEmpty(_ribbonTab.ContextName)) { // Find the context definition for this context KryptonRibbonContext ribbonContext = _ribbon.RibbonContexts[_ribbonTab.ContextName]; // Should always work, but you never know! if (ribbonContext != null) { return(ribbonContext.ContextColor); } } } return(Color.Empty); }