Exemple #1
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            #region Determine items

            int itemsWide = 0;

            switch (e.SizeMode)
            {
            case RibbonElementSizeMode.DropDown:
                itemsWide = ItemsSizeInDropwDownMode.Width;
                break;

            case RibbonElementSizeMode.Large:
                itemsWide = ItemsWideInLargeMode;
                break;

            case RibbonElementSizeMode.Medium:
                itemsWide = ItemsWideInMediumMode;
                break;

            case RibbonElementSizeMode.Compact:
                itemsWide = 0;
                break;
            }

            #endregion

            int  height       = OwnerPanel.ContentBounds.Height - Owner.ItemPadding.Vertical - 4;
            int  scannedItems = 0;
            int  widthSum     = 1;
            int  buttonHeight = 0;
            int  heightSum    = 0;
            bool sumWidth     = true;

            foreach (RibbonButton button in Buttons)
            {
                Size s = button.MeasureSize(this,
                                            new RibbonElementMeasureSizeEventArgs(e.Graphics, this.ButtonsSizeMode));

                if (sumWidth)
                {
                    widthSum += s.Width + 1;
                }

                buttonHeight = button.LastMeasuredSize.Height;
                heightSum   += buttonHeight;

                if (++scannedItems == itemsWide)
                {
                    sumWidth = false;
                }
            }

            if (e.SizeMode == RibbonElementSizeMode.DropDown)
            {
                height = buttonHeight * ItemsSizeInDropwDownMode.Height;
            }

            if (ScrollBarRenderer.IsSupported)
            {
                _thumbBounds = new Rectangle(Point.Empty, ScrollBarRenderer.GetSizeBoxSize(e.Graphics, System.Windows.Forms.VisualStyles.ScrollBarState.Normal));
            }
            else
            {
                _thumbBounds = new Rectangle(Point.Empty, new Size(16, 16));
            }

            //if (height < 0)
            //{
            //    throw new Exception("???");
            //}
            SetLastMeasuredSize(new Size(widthSum + ControlButtonsWidth, height));

            return(LastMeasuredSize);
        }