Inheritance: System.ComponentModel.Component
        private Color CheckForContextColor(PaletteState state)
        {
            // We need an associated ribbon tab
            // Does the ribbon tab have a context setting?
            if (!string.IsNullOrEmpty(_ribbon.SelectedTab?.ContextName))
            {
                // Find the context definition for this context
                KryptonRibbonContext ribbonContext = _ribbon.RibbonContexts[_ribbon.SelectedTab.ContextName];

                // Should always work, but you never know!
                if (ribbonContext != null)
                {
                    // Return the context specific color
                    return(ribbonContext.ContextColor);
                }
            }

            return(Color.Empty);
        }
        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);
                }
            }
        }
Beispiel #3
0
        private void buttonAddContext_Click(object sender, EventArgs e)
        {
            // Create a new context that uses the information specified
            KryptonRibbonContext newContext = new KryptonRibbonContext();
            newContext.ContextName = textBoxContextName.Text;
            newContext.ContextTitle = textBoxContextTitle.Text;
            newContext.ContextColor = panelContextColor.StateCommon.Color1;
            kryptonRibbon.RibbonContexts.Add(newContext);

            // Create a new ribbon page that specifies the new context name
            KryptonRibbonTab newTab = new KryptonRibbonTab();
            newTab.ContextName = newContext.ContextName;
            kryptonRibbon.RibbonTabs.Add(newTab);

            // Update the selected context name on the form and control so it shows
            string newSelectedContext = textBoxSelectedContexts.Text;
            if (newSelectedContext.Length > 0)
                newSelectedContext += ",";
            newSelectedContext += newContext.ContextName;
            textBoxSelectedContexts.Text = newSelectedContext;
            kryptonRibbon.SelectedContext = newSelectedContext;
        }