Documents for Word .NET Edition
Features / Paragraph / Borders
In This Topic
    Borders
    In This Topic

    GcWord allows you to specify the border properties for a paragraph using the Border class which can be accessed using Borders property of the ParagraphFormat class.

    Get Borders

    To get the borders of a paragraph:

    1. Access a paragraph from the paragraph collection using Paragraphs property of the RangeBase class.
    2. Access the paragraph formatting properties using Format property of the Paragraph class.
    3. Get border collection of the paragraph using Borders property of the ParagraphFormat class.
    4. Get the left and right borders using Left and Right properties of the BorderCollection class respectively.
    5. Get the border style using LineStyle property of the Border class.
    6. Get the border color using Color property of the Border class.
    7. Display the left and right border style and color on the console.
      C#
      Copy Code
      //Get borders
      LineStyle styleLeft = 
          doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Borders.Left.LineStyle;
      LineStyle styleRight = 
          doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Borders.Right.LineStyle;
      Color colorLeft = 
          doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Borders.Left.Color.RGB;
      Color colorRight = 
          doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Borders.Right.Color.RGB;
      Console.WriteLine("Left Border: " + styleLeft + " " + colorLeft);
      Console.WriteLine("Right Border: " + styleRight + " " + colorRight);
    Back to Top

    Set Borders

    To set the borders of a paragraph:

    1. Access a paragraph from the paragraph collection using Paragraphs property of the RangeBase class.
    2. Access the paragraph formatting properties using Format property of the Paragraph class.
    3. Get border collection of the paragraph using Borders property of the ParagraphFormat class.
    4. Get the left and right borders using Left and Right properties of the BorderCollection class respectively.
    5. Set the border style using LineStyle property of the Border class.
    6. Set the border color using Color property of the Border class.
      C#
      Copy Code
      //Set borders
      doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Borders.Left.Color.RGB = Color.Red;
      doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Borders.Left.LineStyle = 
          LineStyle.ChainLink;
      doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Borders.Right.Color.RGB = Color.Yellow;
      doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Borders.Right.LineStyle = 
          LineStyle.ChainLink;
    Back to Top

    For more information on how to implement paragraph borders using GcWord, see GcWord sample browser.