CharacterFormatting.vb
''
'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports GrapeCity.Documents.Word

'' This short sample demonstrates the basics of accessing text content
'' and character formatting in DsWord.
'' It creates a document and adds a paragraph of text to it.
'' It then splits the paragraph into two runs, And assigns different
'' font styles to the two halves of the text.
Public Class CharacterFormatting
    Function CreateDocx() As GcWordDocument
        '' Get a sample paragraph of text
        Dim lorem = LoremIpsumPar()
        Dim doc = New GcWordDocument()
        '' Add the paragraph to the document
        Dim p = doc.Body.Paragraphs.Add(lorem)
        '' The primary way of manipulating objects in DsWord Is via ranges.
        '' Get the range on the paragraph that we've just added:
        Dim r = p.GetRange()
        '' A Run Is a contiguous fragment of a document with uniform formatting.
        '' In our case, we have only one run so far, get it
        Dim Run = r.Runs.First
        '' Set the size of the font on the whole run
        Run.Font.Size = 16
        '' A Text represents a contiguous fragment of text. It also belongs to a Run,
        '' And cannot span multiple runs (a run though can contain several Text's).
        '' Get the text object
        Dim Text = Run.GetRange().Texts.First
        '' Split the text into two halves (Split() returns the 2nd part)
        Dim tIpsum = Text.Split(lorem.Length / 2)
        '' At this point, our run contains two Texts (two halves of the original text).
        '' We now split the run into two corresponding runs so that we can
        '' apply different formatting to the two texts
        Dim rIpsum = Run.Split(tIpsum, InsertLocation.Before)
        '' The 'text' was split into two halves, but the first half can still
        '' be accessed via the 'text' variable.
        '' A text's containing run can always be accessed via ParentRun.
        '' We set the font of the first half to italic
        Text.ParentRun.Font.Italic = True
        '' And the font of the second half to bold
        rIpsum.Font.Bold = True
        '' Done
        Return doc
    End Function
End Class