Borders and Shading

Borders and Shading

Border and shading formatting in Aspose.Words FOSS for .NET is modeled by two related attribute classes: Border, which describes a single border line, and Shading, which describes a background fill pattern. Paragraphs, tables, cells, and fonts each expose a BorderCollection (multiple Border sides) and a single Shading object through their respective formatting properties.


Working with Individual Borders

A Border object represents one border line and exposes LineStyle (an enum value from LineStyle, such as Single, Double, Dot, or Wave), LineWidth, Color, DistanceFromText, Shadow, and theme-aware ThemeColor/TintAndShade properties. Call ClearFormatting() on a Border to reset it to its default (no border) state.

BorderCollection groups multiple Border objects for an object’s sides. It exposes named properties for the four edges — Left, Right, Top, Bottom — plus Horizontal and Vertical for interior table borders. The BorderCollection indexer retrieves a specific side using a BorderType enum value (Left, Right, Top, Bottom, Horizontal, Vertical, DiagonalDown, DiagonalUp, or None) as the key. Setting LineWidth, LineStyle, or Color directly on the collection applies that value to every border it contains at once; ClearFormatting() clears all borders in the collection together.


Applying Shading

Shading carries the background pattern for an object: BackgroundPatternColor and ForegroundPatternColor define the two pattern colors, and Texture (a TextureIndex enum value) selects the pattern — solid fills use TextureIndex.TextureSolid, while percentage and directional patterns (Texture10Percent through Texture97Pt5Percent, TextureHorizontal, TextureDiagonalCross, and others) reproduce Word’s shading gallery. ForegroundPatternThemeColor and BackgroundPatternThemeColor provide theme-color equivalents, alongside tint/shade adjustment via ForegroundTintAndShade and BackgroundTintAndShade. ClearFormatting() resets a Shading object to no fill.


Tips and Best Practices

  • Set Texture to TextureIndex.TextureSolid and use BackgroundPatternColor for a plain background fill — the most common shading case.
  • Use the BorderCollection indexer (borders[BorderType.Horizontal] / borders[BorderType.Vertical]) to reach the interior grid lines of a table, which are not exposed as named properties.
  • Setting properties directly on a BorderCollection (rather than on an individual Left/Right/Top/Bottom Border) is the fastest way to apply uniform borders to all sides.
  • Remember LineStyle.None removes the visible line without clearing the rest of the border’s configured width or color — use ClearFormatting() for a full reset.
  • Table cell and paragraph borders are independent BorderCollection instances; setting one does not affect the other.

Common Issues

IssueCauseFix
Border not visible after setting ColorLineStyle left at LineStyle.NoneSet LineStyle to a visible style such as Single before saving
Shading appears as a solid fill when a pattern was expectedTexture left at its defaultExplicitly set Texture to the desired pattern constant
Interior table borders unaffected by edge border changesHorizontal/Vertical are separate from Left/Right/Top/BottomSet BorderCollection.Horizontal and .Vertical explicitly
BorderCollection indexer returns unexpected borderWrong BorderType value passedConfirm the BorderType enum value matches the intended side

FAQ

How do I apply the same border to all four sides of a table cell?

Set LineStyle, LineWidth, and Color directly on the cell’s BorderCollection rather than on each of Left, Right, Top, and Bottom individually — the collection-level setters apply to every border it contains.

What is the difference between Border and Shading?

Border describes a line (style, width, color) drawn along an edge; Shading describes a background fill pattern behind the content. They are independent — an object can have shading without borders, or borders without shading.

Which enum controls the visual line pattern of a border?

LineStyle, with values such as Single, Double, Dot, DashSmallGap, and Wave.

Can I remove a border entirely?

Yes — call ClearFormatting() on the Border or BorderCollection, or set LineStyle to LineStyle.None.


API Reference Summary

Class / MethodDescription
BorderA single border line: style, width, color, shadow
BorderCollectionThe set of borders (Left, Right, Top, Bottom, Horizontal, Vertical) for an object
BorderTypeEnum identifying a border side
LineStyleEnum of visual line styles (Single, Double, Dot, etc.)
ShadingBackground pattern fill: colors and Texture
TextureIndexEnum of shading pattern textures

See Also