Document Solutions for Word
Features / Paragraph / Background Shading
In This Topic
    Background Shading
    In This Topic

    DsWord allows you to specify the background shading for a paragraph using BackgroundPatternColor property of the Shading class which can be accessed using Shading property of the ParagraphFormat class.

    Get Shading

    To get the shading:

    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. Access the shading formatting for the paragraph using Shading property of the ParagraphFormat class.
    4. Get shading property. For example, get the shading texture using Texture property of the Shading class.
    5. Get the background color using BackgroundPatternColor property of the Shading class.
    6. Display the shading pattern and color on the console.
      C#
      Copy Code
      //Get shading
      TexturePattern texture = 
          doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Shading.Texture;
      Color shading=
          doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Shading.BackgroundPatternColor.RGB;
      Console.WriteLine("Shading Pattern: " + texture + "\n Shading Color: " + shading);
    Back to Top

    Set Shading

    To set the shading:

    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. Access the shading formatting for the paragraph using Shading property of the ParagraphFormat class.
    4. Set a shading property. For example, set the shading texture using Texture property of the Shading class.
    5. Set the background color using BackgroundPatternColor property of the Shading class.
      C#
      Copy Code
      //Set shading
      doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Shading.Texture = 
          TexturePattern.Percent15;
      doc.Body.Sections.First.GetRange().Paragraphs.Last.Format.Shading.BackgroundPatternColor.RGB = 
          Color.LightPink;
    Back to Top

    For more information on how to implement background shading using DsWord, see DsWord sample browser.