'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.GlobalizationImportsGrapeCity.Documents.WordImportsGrapeCity.Documents.Word.Fields '' This sample shows how to use the STYLEREF field options to build a'' "running reference" that always displays the text of the nearest'' preceding paragraph formatted with a given style (e.g. the current'' chapter Or section heading), similar to a running head in a printed'' book.'''' LIMITATION: in DsWord 9.2.0 STYLEREF fields placed in a page header'' or footer are not resolved when exporting to PDF/image.PublicClassStyleRefFieldOptsFunctionCreateDocx() AsGcWordDocumentDim doc = NewGcWordDocument() Dim h1 = doc.Styles(BuiltInStyleId.Heading1)Dim h2 = doc.Styles(BuiltInStyleId.Heading2) '' A few chapters, each with a couple of subsections spread across'' multiple pages via filler text:Dim rnd = Util.NewRandom()For c AsInteger = 1To3 doc.Body.AddParagraph($"Chapter {c}", h1)For s AsInteger = 1To2 doc.Body.AddParagraph($"Chapter {c}, Section {s}", h2)Dim i AsInteger = 0DoWhile i < rnd.Next(4, 6) doc.Body.AddParagraph(Util.LoremIpsumPar()) i += 1Loop '' A "breadcrumb" callout in the middle of the body text:'' both fields always resolve to the nearest preceding'' Heading1/Heading2 paragraph, so this line stays correct'' even if content is inserted or reordered above it.Dim crumb = doc.Body.AddParagraph() crumb.GetRange().Runs.Add("You are reading: ") crumb.AddComplexField(NewStyleRefFieldOptions(doc, h1.Name)) crumb.GetRange().Runs.Add(" → ") crumb.AddComplexField(NewStyleRefFieldOptions(doc, h2.Name))NextNext '' Update fields using a specific culture: doc.UpdateFields(NewGrapeCity.Documents.Word.Layout.WordLayoutSettings() With { .FontCollection = Util.FontCollection, .Culture = CultureInfo.GetCultureInfo("en-US") }) '' Done:Return docEndFunctionEndClass