menu

WinForms

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class WTextRange - WindowsForms API Reference | Syncfusion

    Show / Hide Table of Contents

    Class WTextRange

    Represents the text in the Word document. Each part of text can have separate formatting.

    Inheritance
    System.Object
    OwnerHolder
    XDLSSerializableBase
    Entity
    WidgetBase
    ParagraphItem
    WTextRange
    WField
    Implements
    IXDLSSerializable
    IOfficeRun
    IWTextRange
    IParagraphItem
    IEntity
    Inherited Members
    Entity.Clone()
    Entity.IsComposite
    Entity.NextSibling
    Entity.Owner
    Entity.PreviousSibling
    OwnerHolder.Document
    OwnerHolder.m_doc
    ParagraphItem.ApplyStyle(String)
    ParagraphItem.CloneRun()
    ParagraphItem.Dispose()
    ParagraphItem.IsDeleteRevision
    ParagraphItem.IsInsertRevision
    ParagraphItem.m_charFormat
    ParagraphItem.OwnerMathRunElement
    ParagraphItem.OwnerParagraph
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    XDLSSerializableBase.IXDLSSerializable.ReadXmlAttributes(IXDLSAttributeReader)
    XDLSSerializableBase.IXDLSSerializable.ReadXmlContent(IXDLSContentReader)
    XDLSSerializableBase.IXDLSSerializable.RestoreReference(String, Int32)
    XDLSSerializableBase.IXDLSSerializable.WriteXmlAttributes(IXDLSAttributeWriter)
    XDLSSerializableBase.IXDLSSerializable.WriteXmlContent(IXDLSContentWriter)
    XDLSSerializableBase.IXDLSSerializable.XDLSHolder
    XDLSSerializableBase.ReadXmlAttributes(IXDLSAttributeReader)
    XDLSSerializableBase.RestoreReference(String, Int32)
    XDLSSerializableBase.WriteXmlAttributes(IXDLSAttributeWriter)
    XDLSSerializableBase.XDLSHolder
    Namespace: Syncfusion.DocIO.DLS
    Assembly: Syncfusion.DocIO.Base.dll
    Syntax
    public class WTextRange : ParagraphItem, IXDLSSerializable, IOfficeRun, IWTextRange, IParagraphItem, IEntity, IStringWidget, ISplitLeafWidget, ILeafWidget, IWidget, ITextMeasurable
    Examples

    The following example illustrates how to add a text to the document.

    private void Button1_Click(System.Object sender, System.EventArgs e)
    {
        //Create a new Word document 
        WordDocument document = new WordDocument();
        //Add new section to the document
        IWSection section = document.AddSection();
        //Add new paragraph to the section
        IWParagraph paragraph = section.AddParagraph();
        //Initialize new text range instance
        IWTextRange textrange = new WTextRange(document);
        //Add text and its formatting
        textrange.Text = "A new text is added";
        textrange.CharacterFormat.FontSize = 14;
        textrange.CharacterFormat.Bold = true;
        textrange.CharacterFormat.TextColor = Color.Green;
        //Add text range to the paragraph
        paragraph.Items.Add(textrange);
        //Save the Word document
        document.Save("Sample.docx", FormatType.Docx);
        //Close the document
        document.Close();
    }
    Private Sub button_Click(sender As Object, e As EventArgs)
        'Create a new Word document 
        Dim document As New WordDocument()
        'Add new section to the document
        Dim section As IWSection = document.AddSection()
        'Add new paragraph to the section
        Dim paragraph As IWParagraph = section.AddParagraph()
        'Initialize new text range instance
        Dim textrange As IWTextRange = New WTextRange(document)
        'Add text and its formatting
        textrange.Text = "A new text is added"
        text.CharacterFormat.FontSize = 14
        text.CharacterFormat.Bold = True
        text.CharacterFormat.TextColor = Color.Green
        'Add text range to the paragraph
        paragraph.Items.Add(textrange)
        'Save the Word document
        document.Save("Sample.docx", FormatType.Docx)
        'Close the document
        document.Close()
    End Sub

    Constructors

    WTextRange(IWordDocument)

    Initializes a new instance of the WTextRange class with the specified IWordDocument instance.

    Declaration
    public WTextRange(IWordDocument doc)
    Parameters
    Type Name Description
    IWordDocument doc

    The IWordDocument instance.

    Properties

    CharacterFormat

    Gets the character format(font properties) of the text. Read-only.

    Declaration
    public WCharacterFormat CharacterFormat { get; }
    Property Value
    Type
    WCharacterFormat

    EntityType

    Gets the type of the entity.

    Declaration
    public override EntityType EntityType { get; }
    Property Value
    Type Description
    EntityType

    The EntityType of the current item.

    Overrides
    Entity.EntityType

    Text

    Gets or sets the text.

    Declaration
    public virtual string Text { get; set; }
    Property Value
    Type
    System.String

    Methods

    ApplyCharacterFormat(WCharacterFormat)

    Applies the specified character format to the text.

    Declaration
    public void ApplyCharacterFormat(WCharacterFormat charFormat)
    Parameters
    Type Name Description
    WCharacterFormat charFormat

    The WCharacterFormat to be applied to the text.

    Examples

    The following example illustrates how to add a text to the document.

    private void Button1_Click(System.Object sender, System.EventArgs e)
    {
        //Create a new Word document
        WordDocument document = new WordDocument();
        document.EnsureMinimal();
        //Add new text
        IWTextRange text = document.LastParagraph.AppendText("Hello world");
        //Initialize character format
        WCharacterFormat characterformat = new WCharacterFormat(document);
        characterformat.Bold = true;
        characterformat.Italic = true;
        characterformat.TextColor = Color.Blue;
        //Apply character format
        text.ApplyCharacterFormat(characterformat);
        //Save and close the document
        document.Save("Sample.docx", FormatType.Docx);
        document.Close();
    }
    Private Sub button_Click(sender As Object, e As EventArgs)
        'Create a new Word document
        Dim document As New WordDocument()
        document.EnsureMinimal()
        'Add new text
        Dim text As IWTextRange = document.LastParagraph.AppendText("Hello world")
        'Initialize character format
        Dim characterformat As New WCharacterFormat(document)
        characterformat.Bold = True
        characterformat.Italic = True
        characterformat.TextColor = Color.Blue
        'Apply character format
        text.ApplyCharacterFormat(characterformat)
        'Save and close the document
        document.Save("Sample.docx", FormatType.Docx)
        document.Close()
    End Sub

    CloneImpl()

    Creates a duplicate copy of the text.

    Declaration
    protected override object CloneImpl()
    Returns
    Type Description
    System.Object

    The reference to the newly created WTextRange instance.

    Overrides
    ParagraphItem.CloneImpl()

    CreateLayoutInfo()

    Creates layout information.

    Declaration
    protected override void CreateLayoutInfo()
    Overrides
    WidgetBase.CreateLayoutInfo()

    InitXDLSHolder()

    Registers child objects in XDSL holder.

    Declaration
    protected override void InitXDLSHolder()
    Overrides
    XDLSSerializableBase.InitXDLSHolder()

    ReadXmlContent(IXDLSContentReader)

    Reads object data from xml attributes.

    Declaration
    protected override bool ReadXmlContent(IXDLSContentReader reader)
    Parameters
    Type Name Description
    IXDLSContentReader reader

    The IXDLSContentReader object.

    Returns
    Type Description
    System.Boolean

    The value indicating the presence of xml content.

    Overrides
    XDLSSerializableBase.ReadXmlContent(IXDLSContentReader)

    WriteXmlContent(IXDLSContentWriter)

    Writes object data as inside xml element.

    Declaration
    protected override void WriteXmlContent(IXDLSContentWriter writer)
    Parameters
    Type Name Description
    IXDLSContentWriter writer

    The IXDLSContentWriter object.

    Overrides
    XDLSSerializableBase.WriteXmlContent(IXDLSContentWriter)

    Implements

    IXDLSSerializable
    IOfficeRun
    IWTextRange
    IParagraphItem
    IEntity
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved