/// <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)); }