BorderCollection

BorderCollection class

A collection of Border objects.

To learn more, visit the Programming with Documents documentation article.

public sealed class BorderCollection : IEnumerable<Border>

Properties

NameDescription
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.

Methods

NameDescription
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.

Remarks

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.

Examples

Shows how to insert a paragraph with a top border.

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

Border topBorder = builder.ParagraphFormat.Borders.Top;
topBorder.LineWidth = 4.0d;
topBorder.LineStyle = LineStyle.DashSmallGap;
// Set ThemeColor only when LineWidth or LineStyle setted.
topBorder.ThemeColor = ThemeColor.Accent1;
topBorder.TintAndShade = 0.25d;

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

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

See Also