//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Drawing;usingSystem.Collections.Generic;usingSystem.Linq;usingGrapeCity.Documents.Word; namespaceDsWordWeb.Demos{// This sample demonstrates the use of group shapes.// Group shapes allow to group several shapes, // and apply the same settings (such as fills)// to all grouped shapes at once.publicclassGroupShapes {publicGcWordDocumentCreateDocx() {// Layout constants:constintN = 12;constintNCOLS = 3;constintNROWS = 4;constintSIDEX = 130;constintSIDEY = 120;constintDX = 6;constintDY = 4; var doc = newGcWordDocument(); // Add a few ungrouped shapes to the document:var shapes = AddGeometryTypes(doc, newSizeF(SIDEX, SIDEY), N, true, false); // Spread out the shapes:for (int i = 0; i < NROWS; ++i) {for (int j = 0; j < NCOLS; ++j) {var k = i * NCOLS + j;if (k >= N)break; shapes[k].Position.Horizontal.Offset = (SIDEX + DX) * j; shapes[k].Position.Vertical.Offset = (SIDEY + DY) * i; } } // Add the title: doc.Body.Paragraphs.Insert("Group shape with an image fill", doc.Styles[BuiltInStyleId.Title], InsertLocation.Start); // Add the group containing all added shapes:GroupShape group;using (var shapesRange = doc.Body.GetPersistentRange(shapes[0].Start, shapes.Last().End)) group = shapesRange.GroupShapes.Insert(RangeLocation.Whole); // Adjust the group's size: group.Size.Width.Value = SIDEX * NCOLS + DX * (NCOLS - 1); group.Size.Height.Value = SIDEY * NROWS + DY * (NROWS - 1); // Create an image fill on the group shape: group.Fill.Type = FillType.Image;var bytes = File.ReadAllBytes(Path.Combine("Resources", "Images", "roofs.jpg")); group.Fill.ImageFill.SetImage(bytes, "image/jpeg");// And apply it to the group: group.ApplyGroupFill(); return doc; } /// <summary>/// Adds a paragraph with a single empty run, and adds a shape for each available GeometryType./// The fill and line colors of the shapes are varied./// </summary>/// <paramname="doc">The target document.</param>/// <paramname="size">The size of shapes to create.</param>/// <paramname="count">The maximum number of shapes to create (-1 for no limit).</param>/// <paramname="skipUnfillable">Add only shapes that support fills.</param>/// <paramname="noNames">Do not add geometry names as shape text frames.</param>/// <returns>The list of shapes added to the document.</returns>privatestaticList<Shape> AddGeometryTypes(GcWordDocument doc, SizeF size, int count = -1, bool skipUnfillable = false, bool noNames = false) {// Line and fill colors:Color[] lines = newColor[] { Color.Blue, Color.SlateBlue, Color.Navy, Color.Indigo, Color.BlueViolet, Color.CadetBlue, };int line = 0;Color[] fills = newColor[] { Color.MistyRose, Color.BurlyWood, Color.Coral, Color.Goldenrod, Color.Orchid, Color.Orange, Color.PaleVioletRed, };int fill = 0; // The supported geometry types:var geoms = Enum.GetValues(typeof(GeometryType)); // Add a paragraph and a run where the shapes will live: doc.Body.Paragraphs.Add("");Run run = doc.Body.Runs.Last; var shapes = newList<Shape>();foreach (GeometryType g in geoms) {// Line geometries do not support fills:if (skipUnfillable && g.IsLineGeometry())continue; if (count-- == 0)break; float w = size.Width, h = size.Height;var shape = run.GetRange().Shapes.Add(w, h, g);if (!g.IsLineGeometry()) { shape.Fill.Type = FillType.Solid; shape.Fill.SolidFill.RGB = fills[fill < fills.Length - 1 ? ++fill : (fill = 0)]; } shape.Line.Width = 3; shape.Line.Fill.SolidFill.RGB = lines[line < lines.Length - 1 ? ++line : (line = 0)];if (!noNames && g.TextFrameSupported()) shape.AddTextFrame(g.ToString()); shape.AlternativeText = $"This is shape {g}"; shape.Size.EffectExtent.AllEdges = 8; shapes.Add(shape); }return shapes; } }}