ComponentFactory.Krypton.Ribbon.ViewDrawRibbonGroup.GetPreferredSize C# (CSharp) Method

GetPreferredSize() public method

Discover the preferred size of the element.
public GetPreferredSize ( ViewLayoutContext context ) : Size
context ComponentFactory.Krypton.Toolkit.ViewLayoutContext Layout context.
return System.Drawing.Size
        public override Size GetPreferredSize(ViewLayoutContext context)
        {
            Size preferredSize = base.GetPreferredSize(context);
            preferredSize.Width = Math.Max(preferredSize.Width, MINIMUM_GROUP_WIDTH);
            preferredSize.Height = _ribbon.CalculatedValues.GroupHeight;
            return preferredSize;
        }

Usage Example

示例#1
0
        /// <summary>
        /// Show the group popup relative to the parent group instance.
        /// </summary>
        /// <param name="parentGroup">Parent group instance.</param>
        /// <param name="parentScreenRect">Screen rectangle of the parent.</param>
        public void ShowCalculatingSize(ViewDrawRibbonGroup parentGroup,
                                        Rectangle parentScreenRect)
        {
            Size popupSize;

            // Prevent ribbon from laying out the same group as we are
            // about to get the preferred size from. This reentrancy can
            // happen if the group has a custom control that is then moved
            // to be reparented to the popup group and so therefore cause
            // a layout of the main ribbon.
            _ribbon.SuspendLayout();
            SuspendLayout();

            try
            {
                // Find the size the group requests to be
                using (ViewLayoutContext context = new ViewLayoutContext(this, Renderer))
                    popupSize = _viewGroup.GetPreferredSize(context);

                // Override the height to enforce the correct group height
                popupSize.Height = _ribbon.CalculatedValues.GroupHeight;

                // Mark the group as showing as a popup
                _ribbonGroup.ShowingAsPopup = true;

                // Request we be shown below the parent screen rect
                Show(CalculateBelowPopupRect(parentScreenRect, popupSize));
            }
            finally
            {
                // Reverse the suspend call
                _ribbon.ResumeLayout();
                ResumeLayout();
            }
        }