'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.CollectionsImportsSystem.Collections.GenericImportsSystem.LinqImportsGrapeCity.Documents.Word '' 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.PublicClassGroupShapesFunctionCreateDocx() AsGcWordDocument'' Layout constants:ConstN = 12ConstNCOLS = 3ConstNROWS = 4ConstSIDEX = 130ConstSIDEY = 120ConstDX = 6ConstDY = 4 Dim doc = NewGcWordDocument() '' Add a few ungrouped shapes to the document:Dim shapes = AddGeometryTypes(doc, NewSizeF(SIDEX, SIDEY), N, True, False) '' Spread out the shapes:For i = 0ToNROWS - 1For j = 0ToNCOLS - 1Dim k = i * NCOLS + jIf (k >= N) ThenExitForEndIf shapes(k).Position.Horizontal.Offset = (SIDEX + DX) * j shapes(k).Position.Vertical.Offset = (SIDEY + DY) * iNextNext '' 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:Dim group AsGroupShapeUsing shapesRange = doc.Body.GetPersistentRange(shapes(0).Start, shapes.Last().End) group = shapesRange.GroupShapes.Insert(RangeLocation.Whole)EndUsing '' 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.ImageDim 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 docEndFunction ''' <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>''' <param name="doc">The target document.</param>''' <param name="size">The size of shapes to create.</param>''' <param name="count">The maximum number of shapes to create (-1 for no limit).</param>''' <param name="skipUnfillable">Add only shapes that support fills.</param>''' <param name="noNames">Do not add geometry names as shape text frames.</param>''' <returns>The list of shapes added to the document.</returns>PrivateSharedFunctionAddGeometryTypes(doc AsGcWordDocument, size AsSizeF, Optional count AsInteger = -1, Optional skipUnfillable AsBoolean = False, Optional noNames AsBoolean = False) AsList(OfShape) '' Line and fill colors:Dim lines = NewColor() {Color.Blue, Color.SlateBlue, Color.Navy, Color.Indigo, Color.BlueViolet, Color.CadetBlue}Dim line = 0Dim fills = NewColor() {Color.MistyRose, Color.BurlyWood, Color.Coral, Color.Goldenrod, Color.Orchid, Color.Orange, Color.PaleVioletRed}Dim fill = 0 '' The supported geometry types:Dim geoms AsGeometryType() = [Enum].GetValues(GetType(GeometryType)) '' Add a paragraph and a run where the shapes will live: doc.Body.Paragraphs.Add("")Dim run = doc.Body.Runs.Last Dim shapes = NewList(OfShape)ForEach g In geoms'' Line geometries do not support fills:If skipUnfillable AndAlso g.IsLineGeometry() ThenContinueForEndIfIf count = 0ThenExitForEndIf count -= 1 Dim w = size.Width, h = size.HeightDim shape = run.GetRange().Shapes.Add(w, h, g)IfNot g.IsLineGeometry() Then shape.Fill.Type = FillType.SolidIf fill < fills.Length - 1Then fill += 1Else fill = 0EndIf shape.Fill.SolidFill.RGB = fills(fill)EndIf shape.Line.Width = 3If line < lines.Length - 1Then line += 1Else line = 0EndIf shape.Line.Fill.SolidFill.RGB = lines(line)IfNot noNames AndAlso g.TextFrameSupported() Then shape.AddTextFrame(g.ToString())EndIf shape.AlternativeText = $"This is shape {g}" shape.Size.EffectExtent.AllEdges = 8 shapes.Add(shape)NextReturn shapesEndFunctionEndClass