BorderCollection class

A collection of Border objects.

public sealed class BorderCollection : IEnumerable<Border>


Name Description
Bottom { get; } Gets the bottom border.
Color { get; set; } Gets or sets the border color.
Count { get; } Gets the number of borders in the collection.
DistanceFromText { get; set; } Gets or sets distance of the border from text in points.
Horizontal { get; } Gets the horizontal border that is used between cells or conforming paragraphs.
Item { get; } Retrieves a Border object by border type. (2 indexers)
Left { get; } Gets the left border.
LineStyle { get; set; } Gets or sets the border style.
LineWidth { get; set; } Gets or sets the border width in points.
Right { get; } Gets the right border.
Shadow { get; set; } Gets or sets a value indicating whether the border has a shadow.
Top { get; } Gets the top border.
Vertical { get; } Gets the vertical border that is used between cells.


Name Description
ClearFormatting() Removes all borders of an object.
Equals(BorderCollection) Compares collections of borders.
GetEnumerator() Returns an enumerator object that can be used to iterate over all borders in the collection.


Different document elements have different borders. For example, ParagraphFormat has Bottom, Left, Right and Top borders. You can specify different formatting for each border independently or enumerate through all borders and apply same formatting.


Shows how to insert a paragraph with a top border.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Border topBorder = builder.ParagraphFormat.Borders[BorderType.Top];
topBorder.Color = Color.Red;
topBorder.LineWidth = 4.0d;
topBorder.LineStyle = LineStyle.DashSmallGap;

builder.Writeln("Text with a red top border.");

doc.Save(ArtifactsDir + "Border.ParagraphTopBorder.docx");

See Also