public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
      {
         if (e.SizeMode == RibbonElementSizeMode.DropDown)
         {
             // A horizontal separator on a menu
            if (string.IsNullOrEmpty(Text))
            {
               SetLastMeasuredSize(new Size(1, 2));
            }
            else
            {
               Size sz = e.Graphics.MeasureString(Text, new Font(Owner.Font, FontStyle.Bold)).ToSize();
               SetLastMeasuredSize(new Size(sz.Width + Owner.ItemMargin.Horizontal + 1, sz.Height + Owner.ItemMargin.Vertical));
            }
         }
         else
         {
             // A vertical separator on a Panel or the QAT
             if (OwnerPanel == null)
             {
                 // A vertical separator on the QAT
                 SetLastMeasuredSize(new Size(7, Owner.QuickAccessToolbar.ContentBounds.Height - Owner.QuickAccessToolbar.Padding.Vertical));
             }
             else
             {
                 // A vertical separator on a Panel
                 SetLastMeasuredSize(new Size(4, OwnerPanel.ContentBounds.Height - Owner.ItemPadding.Vertical - Owner.ItemMargin.Vertical));
             }
         }

         return LastMeasuredSize;
      }
示例#2
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
			Size textSize = TextRenderer.MeasureText(Text, Owner.Font);

			Size size = new Size(CheckBoxSize.Width + 6 + textSize.Width,
				Math.Max(CheckBoxSize.Height + 4, Owner.Font.Height + 4));

            SetLastMeasuredSize(size);
            return size;
        }
        /// <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 override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (!this.Visible && ((this.Site == null) || !this.Site.DesignMode))
             {
            return new Size(0, 0);
             }
             Font f = new Font("Microsoft Sans Serif", 8);
             if (Owner != null)
            f = Owner.Font;

             int w = string.IsNullOrEmpty(this.Text) ? 0 : ((this._labelWidth > 0) ? this._labelWidth : (e.Graphics.MeasureString(this.Text, f).ToSize().Width + 6));
             base.SetLastMeasuredSize(new Size(w, this.MeasureHeight()));
             return base.LastMeasuredSize;
        }
示例#4
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (!checkedGlyphSize)
            {
                try
                {
                    if (Style == CheckBoxStyle.CheckBox)
                    {
                        _checkboxSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, Checked == true ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal).Height + spacing;
                    }
                    else
                    {
                        _checkboxSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, Checked == true ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal).Height + spacing;
                    }
                }
                catch { /* I don't mind at all */ }
                checkedGlyphSize = true;
            }

            if (!Visible && !Owner.IsDesignMode())
            {
                SetLastMeasuredSize(new Size(0, 0));
                return(LastMeasuredSize);
            }

            Size size = Size.Empty;

            int w      = Owner.ItemMargin.Horizontal;
            int iwidth = Image != null ? Image.Width + spacing : 0;
            int lwidth = string.IsNullOrEmpty(Text) ? 0 : _labelWidth > 0 ? _labelWidth : e.Graphics.MeasureString(Text, Owner.Font).ToSize().Width;

            w += _checkboxSize;

            switch (e.SizeMode)
            {
            case RibbonElementSizeMode.Large:
                w += iwidth + lwidth;
                break;

            case RibbonElementSizeMode.Medium:
                w += iwidth;
                break;
            }

            SetLastMeasuredSize(new Size(w, MeasureHeight()));

            return(LastMeasuredSize);
        }
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (!Visible && !Owner.IsDesignMode())
            {
                SetLastMeasuredSize(new Size(0, 0));
                return(LastMeasuredSize);
            }

            Size s = base.MeasureSize(sender, e);

            s.Height = 52;

            SetLastMeasuredSize(s);

            return(s);
        }
示例#6
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 override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (!this.Visible && ((this.Site == null) || !this.Site.DesignMode))
            {
                return(new Size(0, 0));
            }
            Font f = new Font("Microsoft Sans Serif", 8);

            if (Owner != null)
            {
                f = Owner.Font;
            }

            int w = string.IsNullOrEmpty(this.Text) ? 0 : ((this._labelWidth > 0) ? this._labelWidth : (e.Graphics.MeasureString(this.Text, f).ToSize().Width + 6));

            base.SetLastMeasuredSize(new Size(w, this.MeasureHeight()));
            return(base.LastMeasuredSize);
        }
示例#7
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)
            {
                if (item.Visible || Owner.IsDesignMode())
                {
                    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
        }
示例#8
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));
        }
示例#9
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;
        }
示例#10
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (e.SizeMode == RibbonElementSizeMode.DropDown)
            {
                if (string.IsNullOrEmpty(Text))
                {
                    SetLastMeasuredSize(new Size(1, 3));
                }
                else
                {
                    var 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);
        }
示例#11
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            var design = ((Site?.DesignMode ?? false) ||
                          IsOpenInVisualStudioDesigner());

            if (design && (Owner != null))
            {
                var       width  = Convert.ToInt32(e.Graphics.MeasureString(Site.Name, Owner.Font).Width);
                const int height = 20;
                if ((width == LastMeasuredSize.Width) &&
                    (height == LastMeasuredSize.Height))
                {
                    return(LastMeasuredSize);
                }
                SetLastMeasuredSize(new Size(width, height));
            }
            else if ((_ctl == null) || !Visible)
            {
                SetLastMeasuredSize(new Size(0, 0));
            }
            else
            {
                if ((_lastSizeMode == e.SizeMode) &&
                    (_ctl.Size.Width == LastMeasuredSize.Width) &&
                    (_ctl.Size.Height == LastMeasuredSize.Height))
                {
                    return(LastMeasuredSize);
                }
                _ctl.Visible = false;
                if (_lastSizeMode != e.SizeMode)
                {
                    _lastSizeMode = e.SizeMode;
                    var hev = new RibbonHostSizeModeHandledEventArgs(e.Graphics, e.SizeMode);
                    OnSizeModeChanging(ref hev);
                }
                SetLastMeasuredSize(new Size(_ctl.Size.Width, _ctl.Size.Height));
            }
            return(LastMeasuredSize);
        }
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            ///For RibbonItemGroup, size is always compact, and it's designed to be on an horizontal flow
            ///tab panel.
            ///
            if (!Visible || !Owner.CaptionBarVisible)
            {
                SetLastMeasuredSize(new Size(0, 0));
                return(LastMeasuredSize);
            }

            int widthSum  = Padding.Horizontal;
            int maxHeight = 16;

            foreach (RibbonItem item in Items)
            {
                if (item.Equals(DropDownButton))
                {
                    continue;
                }
                item.SetSizeMode(RibbonElementSizeMode.Compact);
                Size s = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(e.Graphics, RibbonElementSizeMode.Compact));
                widthSum += s.Width + 1;
                maxHeight = Math.Max(maxHeight, s.Height);
            }

            widthSum -= 1;

            if (Site != null && Site.DesignMode)
            {
                widthSum += 16;
            }

            Size result = new Size(widthSum, maxHeight);

            SetLastMeasuredSize(result);
            return(result);
        }
示例#13
0
        /// <summary>
        /// Measures the size when flow direction is to bottom
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private Size MeasureSizeFlowsToBottom(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            int curRight        = Owner.PanelMargin.Left + Owner.ItemPadding.Horizontal;
            int curBottom       = ContentBounds.Top + Owner.ItemPadding.Vertical;
            int lastRight       = 0;
            int lastBottom      = 0;
            int availableHeight = OwnerTab.TabContentBounds.Height - Owner.TabContentMargin.Vertical - Owner.PanelPadding.Vertical - Owner.PanelMargin.Vertical;
            int maxRight        = 0;
            int maxBottom       = 0;

            foreach (RibbonItem item in Items)
            {
                if (item.Visible || Owner.IsDesignMode() || item.GetType() == typeof(RibbonSeparator))
                {
                    Size itemSize = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(e.Graphics, e.SizeMode));

                    if (curBottom + itemSize.Height > ContentBounds.Bottom)
                    {
                        curBottom = ContentBounds.Top + Owner.ItemPadding.Vertical + 0;
                        curRight  = maxRight + Owner.ItemPadding.Horizontal + 0;
                    }

                    Rectangle bounds = new Rectangle(curRight, curBottom, itemSize.Width, itemSize.Height);

                    lastRight  = bounds.Right;
                    lastBottom = bounds.Bottom;

                    curBottom = bounds.Bottom + Owner.ItemPadding.Vertical + 1;

                    maxRight  = Math.Max(maxRight, lastRight);
                    maxBottom = Math.Max(maxBottom, lastBottom);
                }
            }

            return(new Size(maxRight + Owner.ItemPadding.Right + Owner.PanelMargin.Right + 1, 0)); //Height is provided by MeasureSize
        }
示例#14
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (!Visible && !Owner.IsDesignMode())
            {
                SetLastMeasuredSize(new Size(0, 0));
                return(LastMeasuredSize);
            }

            ///For RibbonItemGroup, size is always compact, and it's designed to be on an horizontal flow
            ///tab panel.
            ///
            int minWidth  = 16;
            int widthSum  = 0;
            int maxHeight = 16;

            foreach (RibbonItem item in Items)
            {
                Size s = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(e.Graphics, RibbonElementSizeMode.Compact));
                widthSum += s.Width + 1;
                maxHeight = Math.Max(maxHeight, s.Height);
            }

            widthSum -= 1;

            widthSum = Math.Max(widthSum, minWidth);

            if (Site != null && Site.DesignMode)
            {
                widthSum += 10;
            }

            Size result = new Size(widthSum, maxHeight);

            SetLastMeasuredSize(result);
            return(result);
        }
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            ///For RibbonItemGroup, size is always compact, and it's designed to be on an horizontal flow
            ///tab panel.
            ///
            if (!Visible || !Owner.CaptionBarVisible)
            {
                SetLastMeasuredSize(new Size(0, 0));
                return LastMeasuredSize;
            }

            int widthSum = Padding.Horizontal;
            int maxHeight = 16;

            foreach (RibbonItem item in Items)
            {
                if (item.Equals(DropDownButton)) continue;
                item.SetSizeMode(RibbonElementSizeMode.Compact);
                Size s = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(e.Graphics, RibbonElementSizeMode.Compact));
                widthSum += s.Width + 1;
                maxHeight = Math.Max(maxHeight, s.Height);
            }

            widthSum -= 1;

            if (Site != null && Site.DesignMode) widthSum += 16;

            Size result = new Size(widthSum, maxHeight);
            SetLastMeasuredSize(result);
            return result;
        }
示例#16
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 = TextRenderer.MeasureText(Text, Owner.Font);
                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);
        }
		/// <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)
		{
			if (!Visible && !Owner.IsDesignMode()) return new Size(0, 0);

         return Size.Ceiling(e.Graphics.MeasureString(string.IsNullOrEmpty(Text) ? " " : Text, Owner.Font));
		}
 public abstract Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e);
示例#19
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)
        {
            if (!Visible && !(this.Site != null && this.Site.DesignMode)) return new Size(0, 0);

             Size textSize = TextRenderer.MeasureText(Text, Owner.Font);
             return textSize;
        }
        /// <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;

            if (!Visible && !Owner.IsDesignMode()) return new Size(0, 0);

             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.Left:
               result = MeasureSizeFlowsToBottom(sender, e);
               break;
            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);
        }
示例#21
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 = TextRenderer.MeasureText(Text, Owner.Font);
                    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;
        }
示例#22
0
 public abstract Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e);
        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;
            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;

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

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

            SetLastMeasuredSize(new Size(widthSum + ControlButtonsWidth, height));

            return LastMeasuredSize;
        }
      public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
      {
         if (!Visible && !Owner.IsDesignMode())
         {
            SetLastMeasuredSize(new Size(0, 0));
            return LastMeasuredSize;
         }

         #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("???");
         //}

         //Got off the patch site from logicalerror
         //SetLastMeasuredSize(new Size(widthSum + ControlButtonsWidth, height));
         SetLastMeasuredSize(new Size(Math.Max(0, widthSum + ControlButtonsWidth), Math.Max(0, height)));

         return LastMeasuredSize;
      }
示例#25
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)
        {
            if (!Visible && !Owner.IsDesignMode()) {
                SetLastMeasuredSize(new Size(0, 0));
                return LastMeasuredSize;
            }

            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);
                        //Got off the patch site from logicalerror
                        //heightSum = largeHeight;
                        heightSum = Math.Max(0, largeHeight);
                    } else {
                        widthSum += img.Width;
                        heightSum += img.Height;
                    }

                    break;
                case RibbonElementSizeMode.DropDown:
                    sz = TextRenderer.MeasureText(Text, Owner.Font);
                    if (!string.IsNullOrEmpty(Text)) widthSum += sz.Width + 1;
                    widthSum += simg.Width + Owner.ItemMargin.Horizontal;
                    heightSum += Math.Max(sz.Height, simg.Height);
                    heightSum += 2;
                    break;
                case RibbonElementSizeMode.Medium:
                    sz = TextRenderer.MeasureText(Text, Owner.Font);
                    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;
            //}
            switch (Style) {
                case RibbonButtonStyle.DropDown:
                case RibbonButtonStyle.SplitDropDown:  // drawing size calculation for DropDown and SplitDropDown is identical
                    widthSum += arrowWidth;// + _dropDownMargin.Horizontal;
                    break;
                case RibbonButtonStyle.DropDownListItem:
                    break;
            }

            //check the minimum and mazimum size properties but only in large mode
            if (theSize == RibbonElementSizeMode.Large) {
                //Minimum Size
                if (MinimumSize.Height > 0 && heightSum < MinimumSize.Height)
                    heightSum = MinimumSize.Height;
                if (MinimumSize.Width > 0 && widthSum < MinimumSize.Width)
                    widthSum = MinimumSize.Width;

                //Maximum Size
                if (MaximumSize.Height > 0 && heightSum > MaximumSize.Height)
                    heightSum = MaximumSize.Height;
                if (MaximumSize.Width > 0 && widthSum > MaximumSize.Width)
                    widthSum = MaximumSize.Width;
            }

            SetLastMeasuredSize(new Size(widthSum, heightSum));

            return LastMeasuredSize;
        }
示例#26
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)
		{
			if (!Visible && !Owner.IsDesignMode()) return new Size(0, 0);

            Size textSize = TextRenderer.MeasureText(Text, Owner.RibbonTabFont);
			return textSize;
		}
 /// <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 override System.Drawing.Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
 {
     if (Site != null && Site.DesignMode && Owner != null)
      {
     //when in design mode just paint the name of this control
     int Width = Convert.ToInt32(e.Graphics.MeasureString(Site.Name, Owner.Font).Width);
     int Height = 20;
     SetLastMeasuredSize(new System.Drawing.Size(Width, Height));
      }
      else if (ctl == null || !Visible)
     SetLastMeasuredSize(new System.Drawing.Size(0, 0));
      else
      {
     ctl.Visible = false;
     if (_lastSizeMode != e.SizeMode)
     {
        _lastSizeMode = e.SizeMode;
        RibbonHostSizeModeHandledEventArgs hev = new RibbonHostSizeModeHandledEventArgs(e.Graphics, e.SizeMode);
        OnSizeModeChanging(ref hev);
     }
     SetLastMeasuredSize(new System.Drawing.Size(ctl.Size.Width + 2, ctl.Size.Height + 2));
      }
      return LastMeasuredSize;
 }
示例#28
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)
        {
            if (!Visible && !Owner.IsDesignMode())
            {
                SetLastMeasuredSize(new Size(0, 0));
                return(LastMeasuredSize);
            }

            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);
                    //Got off the patch site from logicalerror
                    //heightSum = largeHeight;
                    heightSum = Math.Max(0, largeHeight);
                }
                else
                {
                    widthSum  += img.Width;
                    heightSum += img.Height;
                }

                break;

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

            case RibbonElementSizeMode.Medium:
                sz = Size.Ceiling(e.Graphics.MeasureString(Text, Owner.Font));
                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;
            //}
            switch (Style)
            {
            case RibbonButtonStyle.DropDown:
            case RibbonButtonStyle.SplitDropDown:      // drawing size calculation for DropDown and SplitDropDown is identical
                widthSum += arrowWidth + _dropDownMargin.Horizontal;
                break;

            case RibbonButtonStyle.DropDownListItem:
                break;
            }

            //check the minimum and mazimum size properties but only in large mode
            if (theSize == RibbonElementSizeMode.Large)
            {
                //Minimum Size
                if (MinimumSize.Height > 0 && heightSum < MinimumSize.Height)
                {
                    heightSum = MinimumSize.Height;
                }
                if (MinimumSize.Width > 0 && widthSum < MinimumSize.Width)
                {
                    widthSum = MinimumSize.Width;
                }

                //Maximum Size
                if (MaximumSize.Height > 0 && heightSum > MaximumSize.Height)
                {
                    heightSum = MaximumSize.Height;
                }
                if (MaximumSize.Width > 0 && widthSum > MaximumSize.Width)
                {
                    widthSum = MaximumSize.Width;
                }
            }

            SetLastMeasuredSize(new Size(widthSum, heightSum));

            return(LastMeasuredSize);
        }
      public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
      {
			if (!Visible && !Owner.IsDesignMode())
         {
            SetLastMeasuredSize(new Size(0, 0));
            return LastMeasuredSize;
         }

         Size size = Size.Empty;

         int w = 0;
         int iwidth = Image != null ? Image.Width + spacing : 0;
         int lwidth = string.IsNullOrEmpty(Text) ? 0 : _labelWidth > 0 ? _labelWidth : e.Graphics.MeasureString(Text, Owner.Font).ToSize().Width + spacing;
         int twidth = TextBoxWidth;

         w += TextBoxWidth + _UpDownSize;

         switch (e.SizeMode)
         {
            case RibbonElementSizeMode.Large:
               w += iwidth + lwidth;
               break;
            case RibbonElementSizeMode.Medium:
               w += iwidth;
               break;
         }

         SetLastMeasuredSize(new Size(w, MeasureHeight()));

         return LastMeasuredSize;
      }
示例#30
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            Size s = base.MeasureSize(sender, e);

            s.Height = 52;

            SetLastMeasuredSize(s);

            return s;
        }
        /// <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)
             {
                if (item.Visible || Owner.IsDesignMode())
            {
               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
        }
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (!Visible && !(this.Site != null && this.Site.DesignMode))
             {
            SetLastMeasuredSize(new Size(0, 0));
            return LastMeasuredSize;
             }

             Size s = base.MeasureSize(sender, e);

             s.Height = 52;

             SetLastMeasuredSize(s);

             return s;
        }
        /// <summary>
        /// Measures the size when flow direction is to bottom
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private Size MeasureSizeFlowsToBottom(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            int curRight = Owner.PanelMargin.Left + Owner.ItemPadding.Horizontal;
             int curBottom = ContentBounds.Top + Owner.ItemPadding.Vertical;
             int lastRight = 0;
             int lastBottom = 0;
             int availableHeight = OwnerTab.TabContentBounds.Height - Owner.TabContentMargin.Vertical - Owner.PanelPadding.Vertical - Owner.PanelMargin.Vertical;
             int maxRight = 0;
             int maxBottom = 0;

             foreach (RibbonItem item in Items)
             {
                if (item.Visible || Owner.IsDesignMode() || item.GetType() == typeof(RibbonSeparator))
            {
               Size itemSize = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(e.Graphics, e.SizeMode));

               if (curBottom + itemSize.Height > ContentBounds.Bottom)
               {
                  curBottom = ContentBounds.Top + Owner.ItemPadding.Vertical + 0;
                  curRight = maxRight + Owner.ItemPadding.Horizontal + 0;
               }

               Rectangle bounds = new Rectangle(curRight, curBottom, itemSize.Width, itemSize.Height);

               lastRight = bounds.Right;
               lastBottom = bounds.Bottom;

               curBottom = bounds.Bottom + Owner.ItemPadding.Vertical + 1;

               maxRight = Math.Max(maxRight, lastRight);
               maxBottom = Math.Max(maxBottom, lastBottom);
            }
             }

             return new Size(maxRight + Owner.ItemPadding.Right + Owner.PanelMargin.Right + 1, 0); //Height is provided by MeasureSize
        }
示例#34
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);
        }
示例#35
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            ///For RibbonItemGroup, size is always compact, and it's designed to be on an horizontal flow
            ///tab panel.
            ///
            int minWidth = 16;
            int widthSum = 0;
            int maxHeight = 16;

            foreach (RibbonItem item in Items)
            {
                Size s = item.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(e.Graphics, RibbonElementSizeMode.Compact));
                widthSum += s.Width + 1;
                maxHeight = Math.Max(maxHeight, s.Height);
            }

            widthSum -= 1;

            widthSum = Math.Max(widthSum, minWidth);

            if (Site != null && Site.DesignMode)
            {
                widthSum += 10;
            }

            Size result = new Size(widthSum, maxHeight);
            SetLastMeasuredSize(result);
            return result;
        }
示例#36
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;
        }
示例#37
0
        public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
        {
            if (!Visible && !Owner.IsDesignMode())
            {
                SetLastMeasuredSize(new Size(0, 0));
                return(LastMeasuredSize);
            }

            #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("???");
            //}

            //Got off the patch site from logicalerror
            //SetLastMeasuredSize(new Size(widthSum + ControlButtonsWidth, height));
            SetLastMeasuredSize(new Size(Math.Max(0, widthSum + ControlButtonsWidth), Math.Max(0, height)));

            return(LastMeasuredSize);
        }
      public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e)
      {
         if (!checkedGlyphSize)
         {
            try
            {
               if (Style == CheckBoxStyle.CheckBox)
                  _checkboxSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, Checked == true ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal).Height + spacing;
               else
                  _checkboxSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, Checked == true ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal).Height + spacing;
            }
            catch { /* I don't mind at all */ }
            checkedGlyphSize = true;
         }

         if (!Visible && !Owner.IsDesignMode())
         {
            SetLastMeasuredSize(new Size(0, 0));
            return LastMeasuredSize;
         }

         Size size = Size.Empty;

         int w = Owner.ItemMargin.Horizontal;
         int iwidth = Image != null ? Image.Width + spacing : 0;
         int lwidth = string.IsNullOrEmpty(Text) ? 0 : _labelWidth > 0 ? _labelWidth : e.Graphics.MeasureString(Text, Owner.Font).ToSize().Width;

         w += _checkboxSize;

         switch (e.SizeMode)
         {
             case RibbonElementSizeMode.DropDown:
                 w += iwidth + lwidth + Owner.ItemImageToTextSpacing;
                 break;
             case RibbonElementSizeMode.Large:
               w += iwidth + lwidth;
               break;
            case RibbonElementSizeMode.Medium:
               w += iwidth;
               break;
         }

         SetLastMeasuredSize(new Size(w, MeasureHeight()));

         return LastMeasuredSize;
      }