Documents for Word .NET Edition
Features / Shapes / Shape Format
In This Topic
    Shape Format
    In This Topic

    GcWord allows you to enhance the look of shapes by customizing shape formats. As a shape represents a visual figure containing fill and outline, you can customize its fill format as well as line format.

    Fill Format

    The fill format of a shape can be customized by using FillFormat class which provides PatternFillSolidFillImageFillGradientFill properties that represent relevant fill types. The FillType enumeration can be used to define the active fill type.

    To add gradient type fill format to a shape:

    1. Add a rectangle shape to a Word document by using Add method of ShapeCollection class and pass GeometryType.Rectangle as its parameter.
    2. Set FillType enumeration to Gradient to set gradient fill format.
    3. Add gradient stops at different positions in the shape by using Add method of GradientStopList class.
      C#
      Copy Code
      var doc = new GcWordDocument();
      var run = doc.Body.Paragraphs.Add().GetRange().Runs.Add();
      var shape = run.GetRange().Shapes.Add(300, 300, GeometryType.Rectangle);
      
      //Set fill format to gradient
      shape.Fill.Type = FillType.Gradient;
      
      //create additional gradient stops           
      //position range is 0..100.
      shape.Fill.GradientFill.Stops.Add(ThemeColorId.Light2, 10f);
      shape.Fill.GradientFill.Stops.Add(ThemeColorId.Accent2, 70f);
      shape.Fill.GradientFill.Stops.Add(ThemeColorId.Light2, 87f);
      
      doc.Save("fillformat.docx");
    Back to Top


    Line Format

    The line format of a shape defines appearance of a shape's line. It can be customized by using LineFormat class and can be set to solid, gradient, image, pattern fill types. You can also set various types of line formats like dash type, cap type, join type etc. by using properties of LineFormat class.

    To add solid type line format to a shape:

    1. Add a rectangle shape to a Word document by using Add method of ShapeCollection class and pass GeometryType.Rectangle as its parameter.
    2. Set FillType enumeration to Solid to set solid line format.
    3. Set LineDashType and LineJoinType enumerations to set dash type and join type of line.
      C#
      Copy Code
      var doc = new GcWordDocument();
      var run = doc.Body.Paragraphs.Add().GetRange().Runs.Add();
      var shape = run.GetRange().Shapes.Add(300, 300, GeometryType.Rectangle);
      
      //Set line format to solid
      shape.Line.Fill.Type = FillType.Solid;
      //Set line type to dotted
      shape.Line.DashType = LineDashType.Dot;
      //Set line join type to round
      shape.Line.JoinType = LineJoinType.Round;
      
      doc.Save("lineformat.docx");
    Back to Top