# Textbox

DsWord allows you to add textbox in a document, which is a combination of text rendered on a shape element. Learn more in DsWord docs.

## Content

While adding text in a document, certain kind of formatting and placement restrictions are faced. These restrictions can be overcome by using a textbox which provides the flexibility to add text anywhere in the document and add certain styles and formatting to it. The textbox is also very helpful for creating a blockquote or a sidebar.
DsWord allows you to add textbox in a document which is a combination of text rendered on a shape element. A shape can be added by using the [Shape](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Shape.html) class and the text can be rendered over it by using the [TextFrame](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.TextFrame.html) class. Additionally, DsWord also provides [LinkedTextFrame](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.LinkedTextFrame.html) class which provides additional space for textual content if it does not fit into the original text frame. The **LinkedTextFrame** is only visible when it accommodates any additional content. Each shape can have no more than one TextFrame or LinkedTextFrame.
You can also define the formatting of text frame like its orientation, word wrap, margin, auto-fit shape to text etc. using the [TextFrameFormat](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.TextFrameFormat.html) class.
![Textbox in a Word document](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/textbox.png)

## Add Textbox

To add textbox in a document:

1. Create a new Word document by instantiating the **GcWordDocument** class.
2. Add a paragraph by using the **Add** method of **ParagraphCollection** class.
3. Add a run to the paragraph and shape to the run by using the **Add** method of [RunCollection](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RunCollection.html) and [ShapeCollection](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ShapeCollection.html) class respectively.
4. Add a text frame to the shape by using the [AddTextFrame](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Shape.AddTextFrame.html) method of the **Shape** class.
5. Add a linked text frame which will accommodate the extra text, if any, by using the [AddLinkedTextFrame](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Shape.AddLinkedTextFrame.html) method of **Shape** class.

    ```csharp
    GcWordDocument doc = new GcWordDocument();
    Paragraph para = doc.Body.Paragraphs.Add();
    Run run = para.GetRange().Runs.Add();
    
    //Add shape 
    Shape shape = run.GetRange().Shapes.Add(100, 100);
    
    //Add a text frame along with text on shape  
    TextFrame tf = shape.AddTextFrame("Document Solutions for Word library is a part of Document Solutions " +
        "that aims to be a complete solution to program and work with Word documents");
    
    //Add linked text frame to hold any extra text
    LinkedTextFrame ltf = doc.Body.Paragraphs.Add().GetRange().Runs.Add().GetRange().Shapes.Add(100, 100).AddLinkedTextFrame(tf);
    
    doc.Save("Textbox.docx");
    ```

## Modify Textbox

To modify a textbox:

1. Create a new Word document by instantiating the **GcWordDocument** class.
2. Load the document containing textbox using **Load** method of **GcWordDocument** class.
3. Access the first text frame in the document and set its formatting properties using the [Format](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.TextFrame.Format.html) property of [TextFrame](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.TextFrame.html) class.

    ```csharp
    GcWordDocument doc = new GcWordDocument();
    doc.Load("Textbox.docx");
    
    //Set formatting properties for Textbox
    doc.Body.TextFrames[1].Format.Orientation = TextOrientation.Vertical;
    doc.Body.TextFrames[1].Format.WordWrap = true;
    doc.Body.TextFrames[1].Format.VerticalAnchor = TextVerticalAnchor.Bottom;
    
    doc.Save("Textbox.docx");
    ```

## Delete Textbox

To delete a textbox:

1. Load the document containing textbox using **Load** method of **GcWordDocument** class.
2. Delete the textbox shape by using the [Delete](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ContentObject.Delete.html) method of [ContentObject](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ContentObject.html) class.

    ```csharp
    GcWordDocument doc = new GcWordDocument();
    doc.Load("Textbox.docx");
    
    //Delete the textbox shape
    doc.Body.Paragraphs[1].GetRange().Shapes.First.Delete();
    
    doc.Save("Textbox1.docx");
    ```

> !type=note
> **Note:** You can also export a Word document containing textbox to PDF and image formats. To know more, refer [Export](/document-solutions/dot-net-word-api/docs/online/features/export) topic.