Details for context menu related events.
Inheritance: CancelEventArgs
        /// <summary>
        /// Raises the DropDown event.
        /// </summary>
        /// <param name="finishDelegate">Delegate fired during event processing.</param>
        protected virtual void OnDropDown(EventHandler finishDelegate)
        {
            bool fireDelegate = true;

            if (!Ribbon.InDesignMode)
            {
                // Events only occur when enabled
                if (Enabled)
                {
                    if ((ButtonType == GroupButtonType.DropDown) ||
                        (ButtonType == GroupButtonType.Split))
                    {
                        if (KryptonContextMenu != null)
                        {
                            ContextMenuArgs contextArgs = new ContextMenuArgs(KryptonContextMenu);

                            // Generate an event giving a chance for the krypton context menu strip to
                            // be shown to be provided/modified or the action even to be cancelled
                            if (DropDown != null)
                                DropDown(this, contextArgs);

                            // If user did not cancel and there is still a krypton context menu strip to show
                            if (!contextArgs.Cancel && (contextArgs.KryptonContextMenu != null))
                            {
                                Rectangle screenRect = Rectangle.Empty;

                                // Convert the view for the button into screen coordinates
                                if ((Ribbon != null) && (ClusterButtonView != null))
                                    screenRect = Ribbon.ViewRectangleToScreen(ClusterButtonView);

                                if (CommonHelper.ValidKryptonContextMenu(contextArgs.KryptonContextMenu))
                                {
                                    // Cache the finish delegate to call when the menu is closed
                                    _kcmFinishDelegate = finishDelegate;

                                    // Show at location we were provided, but need to convert to screen coordinates
                                    contextArgs.KryptonContextMenu.Closed += new ToolStripDropDownClosedEventHandler(OnKryptonContextMenuClosed);
                                    if (contextArgs.KryptonContextMenu.Show(this, new Point(screenRect.X, screenRect.Bottom + 1)))
                                        fireDelegate = false;
                                }
                            }
                        }
                        else if (ContextMenuStrip != null)
                        {
                            ContextMenuArgs contextArgs = new ContextMenuArgs(ContextMenuStrip);

                            // Generate an event giving a chance for the context menu strip to be
                            // shown to be provided/modified or the action even to be cancelled
                            if (DropDown != null)
                                DropDown(this, contextArgs);

                            // If user did not cancel and there is still a context menu strip to show
                            if (!contextArgs.Cancel && (contextArgs.ContextMenuStrip != null))
                            {
                                Rectangle screenRect = Rectangle.Empty;

                                // Convert the view for the button into screen coordinates
                                if ((Ribbon != null) && (ClusterButtonView != null))
                                    screenRect = Ribbon.ViewRectangleToScreen(ClusterButtonView);

                                if (CommonHelper.ValidContextMenuStrip(contextArgs.ContextMenuStrip))
                                {
                                    // Do not fire the delegate in this routine, wait for the popup manager to show it
                                    fireDelegate = false;

                                    //...show the context menu below and at th left of the button
                                    VisualPopupManager.Singleton.ShowContextMenuStrip(contextArgs.ContextMenuStrip,
                                                                                      new Point(screenRect.X, screenRect.Bottom + 1),
                                                                                      finishDelegate);
                                }
                            }
                        }
                    }
                }
            }

            // Do we need to fire a delegate stating the click processing has finished?
            if (fireDelegate && (finishDelegate != null))
                finishDelegate(this, EventArgs.Empty);
        }
        /// <summary>
        /// Raises the DropDown event.
        /// </summary>
        /// <param name="finishDelegate">Delegate fired during event processing.</param>
        protected virtual void OnDropDown(EventHandler finishDelegate)
        {
            bool fireDelegate = true;

            if (!Ribbon.InDesignMode)
            {
                // Events only occur when enabled
                if (Enabled)
                {
                    if ((ButtonType == GroupButtonType.DropDown) ||
                        (ButtonType == GroupButtonType.Split))
                    {
                        if (_kryptonContextMenu != null)
                        {
                            UpdateContextMenu();

                            ContextMenuArgs contextArgs = new ContextMenuArgs(_kryptonContextMenu);

                            // Generate an event giving a chance for the krypton context menu strip to
                            // be shown to be provided/modified or the action even to be cancelled
                            if (DropDown != null)
                                DropDown(this, contextArgs);

                            // If user did not cancel and there is still a krypton context menu strip to show
                            if (!contextArgs.Cancel && (contextArgs.KryptonContextMenu != null))
                            {
                                Rectangle screenRect = Rectangle.Empty;

                                // Convert the view for the button into screen coordinates
                                if ((Ribbon != null) && (ColorButtonView != null))
                                    screenRect = Ribbon.ViewRectangleToScreen(ColorButtonView);

                                if (CommonHelper.ValidKryptonContextMenu(contextArgs.KryptonContextMenu))
                                {
                                    // Cache the finish delegate to call when the menu is closed
                                    _kcmFinishDelegate = finishDelegate;

                                    // Decide which separators are needed
                                    DecideOnVisible(_separatorTheme, _colorsTheme);
                                    DecideOnVisible(_separatorStandard, _colorsStandard);
                                    DecideOnVisible(_separatorRecent, _colorsRecent);
                                    DecideOnVisible(_separatorNoColor, _itemsNoColor);
                                    DecideOnVisible(_separatorMoreColors, _itemsMoreColors);

                                    // Monitor relevant events inside the context menu
                                    HookContextMenuEvents(_kryptonContextMenu.Items, true);

                                    // Show at location we were provided, but need to convert to screen coordinates
                                    contextArgs.KryptonContextMenu.Closed += new ToolStripDropDownClosedEventHandler(OnKryptonContextMenuClosed);
                                    if (contextArgs.KryptonContextMenu.Show(this, new Point(screenRect.X, screenRect.Bottom + 1)))
                                        fireDelegate = false;
                                }
                            }
                        }
                    }
                }
            }

            // Do we need to fire a delegate stating the click processing has finished?
            if (fireDelegate && (finishDelegate != null))
                finishDelegate(this, EventArgs.Empty);
        }
Esempio n. 3
0
 private void kryptonRibbon1_ShowRibbonContextMenu(object sender, ComponentFactory.Krypton.Toolkit.ContextMenuArgs e)
 {
     e.Cancel = false;
 }