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; }
/// <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) { 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 }
/// <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 }
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; }
/// <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; #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); }
public override Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e) { Size size = Size.Empty; int w = 0; int iwidth = Image != null ? Image.Width + spacing : 0; int lwidth = string.IsNullOrEmpty(Text) ? 0 : e.Graphics.MeasureString(Text, Owner.Font).ToSize().Width + spacing; int twidth = TextBoxWidth; w += TextBoxWidth; switch (e.SizeMode) { case RibbonElementSizeMode.Large: w += iwidth + lwidth; break; case RibbonElementSizeMode.Medium: w += iwidth; break; } SetLastMeasuredSize(new Size(w, MeasureHeight())); 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) { Size textSize = System.Windows.Forms.TextRenderer.MeasureText(Text, Owner.Font); return textSize; }
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; }
/// <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; }
public abstract Size MeasureSize(object sender, RibbonElementMeasureSizeEventArgs e);