Exemplo n.º 1
0
        /// <summary>
        /// Measures the size of the panel on the mode specified by the event object
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            Size result      = Size.Empty;
            Size minSize     = Size.Empty;
            int  panelHeight = OwnerTab.TabContentBounds.Height - Owner.PanelPadding.Vertical;

            #region Measure width of minSize

            minSize.Width = e.Graphics.MeasureString(Text, Owner.Font).ToSize().Width + Owner.PanelMargin.Horizontal + 1;

            if (ButtonMoreVisible)
            {
                minSize.Width += ButtonMoreBounds.Width + 3;
            }

            #endregion

            if (e.SizeMode == RibbonElementSizeMode.Overflow)
            {
                Size textSize = RibbonButton.MeasureStringLargeSize(e.Graphics, Text, Owner.Font);

                return(new Size(textSize.Width + Owner.PanelMargin.Horizontal, panelHeight));
            }

            switch (FlowsTo)
            {
            case RibbonPanelFlowDirection.Right:
                result = MeasureSizeFlowsToRight(sender, e);
                break;

            case RibbonPanelFlowDirection.Bottom:
                result = MeasureSizeFlowsToBottom(sender, e);
                break;

            default:
                result = Size.Empty;
                break;
            }

            return(new Size(Math.Max(result.Width, minSize.Width), panelHeight));
        }
Exemplo n.º 2
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (e.SizeMode == RibbonElementSizeMode.DropDown)
            {
                if (string.IsNullOrEmpty(Text))
                {
                    SetLastMeasuredSize(new Size(1, 3));
                }
                else
                {
                    Size sz = e.Graphics.MeasureString(Text, new Font(Owner.Font, FontStyle.Bold)).ToSize();
                    SetLastMeasuredSize(new Size(sz.Width + Owner.ItemMargin.Horizontal, sz.Height + Owner.ItemMargin.Vertical));
                }
            }
            else
            {
                SetLastMeasuredSize(new Size(2, OwnerPanel.ContentBounds.Height - Owner.ItemPadding.Vertical - Owner.ItemMargin.Vertical));
            }

            return(LastMeasuredSize);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Measures the size when flow direction is to right
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private Size MeasureSizeFlowsToRight(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            int widthSum     = Owner.PanelMargin.Horizontal;
            int maxWidth     = 0;
            int maxHeight    = 0;
            int dividedWidth = 0;

            foreach (RibbonItem item in Items)
            {
                Size itemSize = item.MeasureSize(this, e);

                widthSum += itemSize.Width + Owner.ItemPadding.Horizontal + 1;

                maxWidth  = Math.Max(maxWidth, itemSize.Width);
                maxHeight = Math.Max(maxHeight, itemSize.Height);
            }

            switch (e.SizeMode)
            {
            case RibbonElementSizeMode.Large:
                dividedWidth = widthSum / 1;     //Show items on one row
                break;

            case RibbonElementSizeMode.Medium:
                dividedWidth = widthSum / 2;     //Show items on two rows
                break;

            case RibbonElementSizeMode.Compact:
                dividedWidth = widthSum / 3;     //Show items on three rows
                break;

            default:
                break;
            }

            //Add padding
            dividedWidth += Owner.PanelMargin.Horizontal;

            return(new Size(Math.Max(maxWidth, dividedWidth) + Owner.PanelMargin.Horizontal, 0)); //Height is provided by MeasureSize
        }
Exemplo n.º 4
0
        /// <summary>
        /// Measures the size of the tab. The tab content bounds is measured by the Ribbon control
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            Size textSize = TextRenderer.MeasureText(Text, Owner.Font);

            return(textSize);
        }
Exemplo n.º 5
0
 public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Measures the size of the button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            RibbonElementSizeMode theSize = GetNearestSize(e.SizeMode);
            int widthSum    = Owner.ItemMargin.Horizontal;
            int heightSum   = Owner.ItemMargin.Vertical;
            int largeHeight = OwnerPanel.ContentBounds.Height - Owner.ItemPadding.Vertical;// -Owner.ItemMargin.Vertical; //58;

            Size simg = SmallImage != null ? SmallImage.Size : Size.Empty;
            Size img  = Image != null ? Image.Size : Size.Empty;
            Size sz   = Size.Empty;

            switch (theSize)
            {
            case RibbonElementSizeMode.Large:
            case RibbonElementSizeMode.Overflow:
                sz = MeasureStringLargeSize(e.Graphics, Text, Owner.Font);
                if (!string.IsNullOrEmpty(Text))
                {
                    widthSum += Math.Max(sz.Width + 1, img.Width);
                    heightSum = largeHeight;
                }
                else
                {
                    widthSum  += img.Width;
                    heightSum += img.Height;
                }

                break;

            case RibbonElementSizeMode.DropDown:
            case RibbonElementSizeMode.Medium:
                sz = e.Graphics.MeasureString(Text, Owner.Font).ToSize();
                if (!string.IsNullOrEmpty(Text))
                {
                    widthSum += sz.Width + 1;
                }
                widthSum  += simg.Width + Owner.ItemMargin.Horizontal;
                heightSum += Math.Max(sz.Height, simg.Height);
                break;

            case RibbonElementSizeMode.Compact:
                widthSum  += simg.Width;
                heightSum += simg.Height;
                break;

            default:
                throw new ApplicationException("SizeMode not supported: " + e.SizeMode.ToString());
            }

            if (theSize == RibbonElementSizeMode.DropDown)
            {
                heightSum += 2;
            }

            if (Style == RibbonButtonStyle.DropDown)
            {
                widthSum += arrowWidth + Owner.ItemMargin.Right;
            }
            else if (Style == RibbonButtonStyle.SplitDropDown)
            {
                widthSum += arrowWidth + Owner.ItemMargin.Horizontal;
            }

            SetLastMeasuredSize(new Size(widthSum, heightSum));

            return(LastMeasuredSize);
        }
Exemplo n.º 8
0
 public abstract Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e);