ComponentFactory.Krypton.Ribbon.VisualPopupAppMenu.Show C# (CSharp) Method

Show() public method

Show the context menu relative to the provided screen rectangle.
public Show ( Rectangle screenRect ) : void
screenRect System.Drawing.Rectangle Screen rectangle.
return void
        public override void Show(Rectangle screenRect)
        {
            // Find the preferred size of the context menu if it could be any size it likes
            Size preferredSize = CalculatePreferredSize();
            Rectangle preferredRect = new Rectangle(screenRect.Location, preferredSize);

            // Get the working area of the monitor that most of the screen rectangle is inside
            Rectangle workingArea = Screen.GetWorkingArea(preferredRect);

            // Limit size of context menu to the working area
            preferredSize.Width = Math.Min(workingArea.Width, preferredSize.Width);
            preferredSize.Height = Math.Min(workingArea.Height, preferredSize.Height);

            Point screenPt = Point.Empty;

            // Find the horizontal position relative to screen rectangle
            screenPt.X = screenRect.Left;
            screenPt.Y = screenRect.Bottom;

            // Limit location of context menu to the working area
            screenPt.X = Math.Max(screenPt.X, workingArea.X);
            screenPt.Y = Math.Max(screenPt.Y, workingArea.Y);

            if ((screenPt.X + preferredSize.Width) > workingArea.Right)
                screenPt.X = workingArea.Right - preferredSize.Width;

            if ((screenPt.Y + preferredSize.Height) > workingArea.Bottom)
                screenPt.Y = workingArea.Bottom - preferredSize.Height;

            // Call base class method that performs actual sizing and display of control
            base.Show(new Rectangle(screenPt, preferredSize));
        }

Usage Example

コード例 #1
0
        private void OnAppButtonClicked(object sender, EventArgs e)
        {
            // We do not operate the application button at design time
            if (_ribbon.InDesignMode)
            {
                OnAppMenuDisposed(this, EventArgs.Empty);
            }
            else
            {
                // Give event handler a change to cancel the open request
                CancelEventArgs cea = new CancelEventArgs();
                _ribbon.OnAppButtonMenuOpening(cea);

                if (cea.Cancel)
                {
                    OnAppMenuDisposed(this, EventArgs.Empty);
                }
                else
                {
                    // Remove any minimized popup window from display
                    if (_ribbon.RealMinimizedMode)
                    {
                        _ribbon.KillMinimizedPopup();
                    }

                    // Give popups a change to cleanup
                    Application.DoEvents();

                    if (!_ribbon.InDesignMode && !_ribbon.IsDisposed)
                    {
                        Rectangle appRectTop;
                        Rectangle appRectBottom;
                        Rectangle appRectShow;

                        if (_ribbon.RibbonShape == PaletteRibbonShape.Office2007)
                        {
                            // Find screen location of the applicaton button lower half
                            Rectangle appButtonRect = _ribbon.RectangleToScreen(_layoutAppButton.AppButton.ClientRectangle);
                            appRectBottom = new Rectangle(appButtonRect.X, appButtonRect.Y + 22, appButtonRect.Width, appButtonRect.Height - 21);
                            appRectTop    = new Rectangle(appRectBottom.X, appRectBottom.Y - 21, appRectBottom.Width, 21);
                            appRectShow   = appRectBottom;
                        }
                        else
                        {
                            // Find screen location of the applicaton tab lower half
                            Rectangle appButtonRect = _ribbon.RectangleToScreen(_layoutAppTab.AppTab.ClientRectangle);
                            appRectBottom = Rectangle.Empty;
                            appRectTop    = appButtonRect;
                            appRectShow   = new Rectangle(appButtonRect.X, appButtonRect.Bottom - 1, appButtonRect.Width, 0);
                        }

                        // Create the actual control used to show the context menu
                        _appMenu = new VisualPopupAppMenu(_ribbon, _ribbon.RibbonAppButton,
                                                          _ribbon.Palette, _ribbon.PaletteMode,
                                                          _ribbon.GetRedirector(),
                                                          appRectTop, appRectBottom,
                                                          _appButtonController.Keyboard);

                        // Need to know when the visual control is removed
                        _appMenu.Disposed += new EventHandler(OnAppMenuDisposed);

                        // Adjust the screen rect of the app button/tab, so we show half way down the button
                        appRectShow.X     -= 3;
                        appRectShow.Height = 0;

                        // Request the menu be shown immediately
                        _appMenu.Show(appRectShow);

                        // Indicate the context menu is fully constructed and displayed
                        _ribbon.OnAppButtonMenuOpened(EventArgs.Empty);
                    }
                }
            }
        }