'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.DrawingImportsSystem.CollectionsImportsSystem.Collections.GenericImportsSystem.LinqImportsGrapeCity.Documents.Word '' This sample demonstrates the available predefined themed shape styles'' that are supported by DsWord.'' We first generate a number of different shapes with varying fill'' and line colors, then duplicate that shape, and apply a themed style'' to the copy.PublicClassThemedShapeStylesFunctionCreateDocx() AsGcWordDocument Dim styles = GetType(ThemedShapeStyle).GetFields(System.Reflection.BindingFlags.PublicOrSystem.Reflection.BindingFlags.Static).Where(Function(p_) p_.FieldType = GetType(ThemedShapeStyle))Dim stylesCount = styles.Count()Dim doc = NewGcWordDocument() '' We will apply each preset to 2 consecutive shapes:Dim shapes = AddGeometryTypes(doc, NewSizeF(100, 100), stylesCount * 2, True, True) doc.Body.Paragraphs.Insert($"Themed Shape Styles ({stylesCount})", doc.Styles(BuiltInStyleId.Title), InsertLocation.Start) If (shapes.Count() > stylesCount * 2) Then shapes.Skip(stylesCount).ToList().ForEach(Sub(s_) s_.Delete())EndIf Dim styleIdx = 0Dim flop = 0ForEach s In shapesDim shape AsShape = s.GetRange().CopyTo(s.GetRange(), InsertLocation.After).ParentObject Dim style = styles.ElementAt(styleIdx)If (flop Mod2) <> 0Then styleIdx += 1EndIf flop += 1'' Apply the themed style to the shape: shape.ApplyThemedStyle(CType(style.GetValue(Nothing), ThemedShapeStyle))'' Insert the style's name in front of the styled shape: shape.GetRange().Runs.Insert($"{style.Name}:", InsertLocation.Before) shape.GetRange().Runs.Insert(vbCrLf, InsertLocation.After)Next 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 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 = doc.Body.Runs.Last.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