示例#1
0
文件: RibbonPanel.cs 项目: gybing/dms
        /// <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));
        }
示例#2
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (e.SizeMode == RibbonElementSizeMode.DropDown)
            {
                if (string.IsNullOrEmpty(Text))
                {
                    return(new Size(1, 1));
                }
                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);
        }
示例#3
0
文件: RibbonPanel.cs 项目: gybing/dms
        /// <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
        }
示例#4
0
文件: RibbonTab.cs 项目: gybing/dms
        /// <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);
        }
示例#5
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 == null ? 0 : 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);
        }
示例#6
0
 public abstract Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e);