ComponentFactory.Krypton.Navigator.VisualPopupPage.ShowCalculatingSize C# (CSharp) Method

ShowCalculatingSize() public method

Show the group popup relative to the parent group instance.
public ShowCalculatingSize ( Rectangle parentScreenRect ) : void
parentScreenRect System.Drawing.Rectangle Screen rectangle of the parent.
return void
        public void ShowCalculatingSize(Rectangle parentScreenRect)
        {
            // Get the size the popup would like to be
            Size popupSize = ViewManager.GetPreferredSize(Renderer, Size.Empty);

            // Get the resolved position for the popup page
            PopupPagePosition position = _navigator.ResolvePopupPagePosition();

            // Find the size and position relative to the parent screen rect
            switch (position)
            {
                case PopupPagePosition.AboveNear:
                    parentScreenRect = new Rectangle(parentScreenRect.Left, parentScreenRect.Top - _navigator.PopupPages.Gap - popupSize.Height, popupSize.Width, popupSize.Height);
                    break;
                case PopupPagePosition.AboveMatch:
                    parentScreenRect = new Rectangle(parentScreenRect.Left, parentScreenRect.Top - _navigator.PopupPages.Gap - popupSize.Height, parentScreenRect.Width, popupSize.Height);
                    break;
                case PopupPagePosition.AboveFar:
                    parentScreenRect = new Rectangle(parentScreenRect.Right - popupSize.Width, parentScreenRect.Top - _navigator.PopupPages.Gap - popupSize.Height, popupSize.Width, popupSize.Height);
                    break;
                case PopupPagePosition.BelowNear:
                    parentScreenRect = new Rectangle(parentScreenRect.Left, parentScreenRect.Bottom + _navigator.PopupPages.Gap, popupSize.Width, popupSize.Height);
                    break;
                case PopupPagePosition.BelowMatch:
                    parentScreenRect = new Rectangle(parentScreenRect.Left, parentScreenRect.Bottom + _navigator.PopupPages.Gap, parentScreenRect.Width, popupSize.Height);
                    break;
                case PopupPagePosition.BelowFar:
                    parentScreenRect = new Rectangle(parentScreenRect.Right - popupSize.Width, parentScreenRect.Bottom + _navigator.PopupPages.Gap, popupSize.Width, popupSize.Height);
                    break;
                case PopupPagePosition.FarBottom:
                    parentScreenRect = new Rectangle(parentScreenRect.Right + _navigator.PopupPages.Gap, parentScreenRect.Bottom - popupSize.Height, popupSize.Width, popupSize.Height);
                    break;
                case PopupPagePosition.FarMatch:
                    parentScreenRect = new Rectangle(parentScreenRect.Right + _navigator.PopupPages.Gap, parentScreenRect.Top, popupSize.Width, parentScreenRect.Height);
                    break;
                case PopupPagePosition.FarTop:
                    parentScreenRect = new Rectangle(parentScreenRect.Right + _navigator.PopupPages.Gap, parentScreenRect.Top, popupSize.Width, popupSize.Height);
                    break;
                case PopupPagePosition.NearBottom:
                    parentScreenRect = new Rectangle(parentScreenRect.Left - _navigator.PopupPages.Gap - popupSize.Width, parentScreenRect.Bottom - popupSize.Height, popupSize.Width, popupSize.Height);
                    break;
                case PopupPagePosition.NearMatch:
                    parentScreenRect = new Rectangle(parentScreenRect.Left - _navigator.PopupPages.Gap - popupSize.Width, parentScreenRect.Top, popupSize.Width, parentScreenRect.Height);
                    break;
                case PopupPagePosition.NearTop:
                    parentScreenRect = new Rectangle(parentScreenRect.Left - _navigator.PopupPages.Gap - popupSize.Width, parentScreenRect.Top, popupSize.Width, popupSize.Height);
                    break;
            }

            PopupPageEventArgs e = new PopupPageEventArgs(_page,
                                                          _navigator.Pages.IndexOf(_page),
                                                          parentScreenRect);

            // Use event to allow the popup to be cancelled or the position altered
            _navigator.OnDisplayPopupPage(e);

            // Do we need to kill ourself
            if (!e.Cancel)
                Show(e.ScreenRect);
            else
                Dispose();
        }

Usage Example

Beispiel #1
0
        internal void ShowPopupPage(KryptonPage page,
                                    ViewBase relative,
                                    EventHandler finishDelegate)
        {
            Debug.Assert(page != null);
            Debug.Assert(relative != null);

            bool delayDelegate = false;

            // We must have a page and relative element in order to show popup
            if (!DesignMode && (page != null) && (relative != null))
            {
                // Do not show if in the 'Never' show mode
                if (_popupPages.AllowPopupPages != PopupPageAllow.Never)
                {
                    // Check other allow options
                    if ((_popupPages.AllowPopupPages != PopupPageAllow.OnlyOutlookMiniMode) ||
                        (NavigatorMode == NavigatorMode.OutlookMini))
                    {
                        // Do not need to fire delegate until popup page is dismissed
                        delayDelegate = true;

                        // Create the popup window for the group
                        _visualPopupPage = new VisualPopupPage(this, page, Renderer);

                        // We need to know when disposed so the pressed state can be reversed
                        _visualPopupPage.DismissedDelegate = finishDelegate;
                        _visualPopupPage.Disposed += new EventHandler(OnVisualPopupPageDisposed);

                        // Get the client rectangle for the appropriate relative element
                        Rectangle clientRect = (PopupPages.Element == PopupPageElement.Item ?
                                                relative.ClientRectangle : ClientRectangle);

                        // Ask the popup to show itself relative to ourself
                        _visualPopupPage.ShowCalculatingSize(RectangleToScreen(clientRect));
                    }
                }
            }

            if (!delayDelegate && (finishDelegate != null))
                finishDelegate(this, EventArgs.Empty);
        }