/// <summary> /// Returns amount of spacing for specified style parts. /// </summary> /// <param name="es">Style to calculate spacing for.</param> /// <param name="part">Part of the style spacing is calculated for. Values can be combined.</param> /// <param name="side">Side of the style to use for calculation.</param> /// <returns></returns> public static int StyleSpacing(ElementStyle style, eSpacePart part, eStyleSide side) { bool disposeStyle = false; ElementStyle es = ElementStyleDisplay.GetElementStyle(style, out disposeStyle); int space=0; if((part & eSpacePart.Margin)==eSpacePart.Margin) { switch(side) { case eStyleSide.Bottom: space+=es.MarginBottom; break; case eStyleSide.Left: space+=es.MarginLeft; break; case eStyleSide.Right: space+=es.MarginRight; break; case eStyleSide.Top: space+=es.MarginTop; break; } } if((part & eSpacePart.Padding)==eSpacePart.Padding) { switch(side) { case eStyleSide.Bottom: space+=es.PaddingBottom; break; case eStyleSide.Left: space+=es.PaddingLeft; break; case eStyleSide.Right: space+=es.PaddingRight; break; case eStyleSide.Top: space+=es.PaddingTop; break; } } if((part & eSpacePart.Border)==eSpacePart.Border) { switch(side) { case eStyleSide.Bottom: { if(es.PaintBottomBorder) space+=es.BorderBottomWidth; if (es.BorderBottom == eStyleBorderType.Etched || es.BorderBottom == eStyleBorderType.Double) space += es.BorderBottomWidth; break; } case eStyleSide.Left: { if(es.PaintLeftBorder) space+=es.BorderLeftWidth; if (es.BorderLeft == eStyleBorderType.Etched || es.BorderLeft == eStyleBorderType.Double) space += es.BorderLeftWidth; break; } case eStyleSide.Right: { if(es.PaintRightBorder) space+=es.BorderRightWidth; if (es.BorderRight == eStyleBorderType.Etched || es.BorderRight == eStyleBorderType.Double) space += es.BorderRightWidth; break; } case eStyleSide.Top: { if(es.PaintTopBorder) space+=es.BorderTopWidth; if (es.BorderTop == eStyleBorderType.Etched || es.BorderTop == eStyleBorderType.Double) space += es.BorderTopWidth; break; } } } if (disposeStyle) es.Dispose(); return space; }
/// <summary> /// Returns total white space for left side of the style. Whitespace is the space between the edge of the element and inner content of the element. /// </summary> /// <param name="es">Style to return white space for.</param> /// <returns></returns> public static int LeftWhiteSpace(ElementStyle es, eSpacePart parts) { return ElementStyleLayout.StyleSpacing(es, parts, eStyleSide.Left); }
/// <summary> /// Returns total white space for top side of the style. Whitespace is the space between the edge of the element and inner content of the element. /// </summary> /// <param name="es">Style to return white space for.</param> /// <returns></returns> public static int BottomWhiteSpace(ElementStyle es, eSpacePart parts) { return ElementStyleLayout.StyleSpacing(es, parts, eStyleSide.Bottom); }