# Fields and Subtext Parts

> List the MS Word fields and links of every header, footer and text frame with TextParts in Windows Forms, read field codes and mark ranges with SubTextPart.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Document Processing > Fields and Subtext Parts
- **1766 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/fields/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/fields/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/fields/llms-full.txt

---

Fields mark the pieces of a document that your code has to find again: a customer name, a link to a website, a bookmark, a Word merge field. Subtext parts do the same for longer ranges, such as a clause of a contract or an address block, and can carry data of their own. In a Windows Forms application, both work in code and in the editor: the user clicks a link, your application opens it; the input position enters a clause, your application shows its data.

Each example is a handler in *Form1.cs* with the `TextControl` named `textControl1`. Filling merge fields with data is the subject of [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/fields/llms-full.txt), form fields are covered in [Forms and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/form-fields/llms-full.txt), and page numbers in [Sections, Pages, Headers, and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/sections-headers/llms-full.txt).

### The Kinds of Fields

A field is a marked piece of text with a name, an ID and other properties: a [TextField](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textfield/llms-full.txt), an [ApplicationField](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/applicationfield/llms-full.txt) of MS Word, a [HypertextLink](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/hypertextlink/llms-full.txt), a bookmark ([DocumentTarget](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttarget/llms-full.txt)) or a [DocumentLink](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documentlink/llms-full.txt) to a bookmark. [Kinds of Fields](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/fields/#kinds-of-fields) lists their collections. The collections of `TextControl` contain the fields of the text part with the input focus only, and fields of MS Word documents become application fields only when [LoadSettings.ApplicationFieldFormat](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/loadsettings/applicationfieldformat-property/llms-full.txt) is set before loading.

### Insert a Text Field

A text field is inserted at the input position with [TextFieldCollection.Add](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textfieldcollection/add-method/llms-full.txt), after [CanAdd](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textfieldcollectionbase/canadd-property/llms-full.txt) has confirmed that a field can go there. [Insert and Fill Text Fields](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/fields/#insert-and-fill-text-fields) inserts a field for a customer name, fills it and explains `Name`, `ID`, `HighlightMode`, `Editable` and `Deleteable`.

### Add Hypertext Links and Bookmarks

A hypertext link points to a website or a file, a bookmark marks a position, and a document link points to a bookmark. Each is inserted at the input position with the `Add` method of its collection, as [Insert Hyperlinks and Bookmarks](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/fields/#insert-hyperlinks-and-bookmarks) shows, together with the formatting of links inserted in code.

### Open Links When the User Clicks Them

The editor does not open links by itself. It raises [HypertextLinkClicked](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/hypertextlinkclicked-event/llms-full.txt) or [DocumentLinkClicked](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/documentlinkclicked-event/llms-full.txt), and your application decides what the click does. [Handle Clicks on Links](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/fields/#handle-clicks-on-links) opens websites, jumps to bookmarks and opens linked files, and [Find, List and Remove Fields](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/fields/#find-list-and-remove-fields) lists the events of text fields, such as `TextFieldClicked`.

### Find the Fields of All Text Parts

To reach every field of a document, including headers, footers and text frames, loop through `TextParts`. Each part implements [IFormattedText](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/iformattedtext/llms-full.txt), which has the same field collections. The following handler loads an MS Word document with its fields and lists them in a message box; it needs `using System.Text;` at the top of *Form1.cs*:

```csharp
private void listFieldsButton_Click(object sender, EventArgs e)
{
    TXTextControl.LoadSettings loadSettings = new TXTextControl.LoadSettings()
    {
        ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord
    };

    textControl1.Load("template.docx", TXTextControl.StreamType.WordprocessingML, loadSettings);

    StringBuilder list = new StringBuilder();

    foreach (TXTextControl.IFormattedText textPart in textControl1.TextParts)
    {
        foreach (TXTextControl.ApplicationField field in textPart.ApplicationFields)
        {
            list.AppendLine($"{textPart.GetType().Name}: {field.TypeName} = \"{field.Text}\"");
        }

        foreach (TXTextControl.HypertextLink link in textPart.HypertextLinks)
        {
            list.AppendLine($"{textPart.GetType().Name}: link to {link.Target}");
        }
    }

    MessageBox.Show(list.ToString());
}
```

For an application field, [TypeName](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/applicationfield/typename-property/llms-full.txt) is the Word field type, such as `MERGEFIELD`, and [Parameters](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/applicationfield/parameters-property/llms-full.txt) holds the rest of the field code. [Work With MS Word Fields](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/fields/#work-with-ms-word-fields) changes these fields and turns them into plain text with `Clear(true)`.

### Mark Ranges With Subtext Parts

A [SubTextPart](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpart/llms-full.txt) marks a continuous range of text, such as a clause, with a name, an ID and a string of data of your own, for example JSON. Merge blocks are subtext parts too, as [Merge Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/blocks/llms-full.txt) explains. [Subtext Parts](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/subtext-parts/llms-full.txt) creates, finds, saves and removes them, describes the events that report when the user enters one, and lists which formats keep them. To mark a whole paragraph, pass [Paragraph.Start](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/paragraph/start-property/llms-full.txt), which is one-based like the start position of the `SubTextPart` constructor, and the paragraph's `Length` minus 1, so that the paragraph end stays outside.

### Next Steps

- [Fields, Hyperlinks, and Bookmarks](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/fields/llms-full.txt): the dialog boxes and ribbon commands for fields.
- [Subtext Parts](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/subtext-parts/llms-full.txt): subtext parts in the user interface.
- [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/fields/llms-full.txt): fill merge fields with data.
- [Forms and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/form-fields/llms-full.txt): fields that users fill out.
- [Content Controls and Word Form Fields](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/content-controls/llms-full.txt): content controls, legacy form fields and the field adapter classes.

---

## Nearby

- **Previous:** [Sections, Pages, Headers, and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/sections-headers/llms-full.txt)
- **Next:** [Forms and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/form-fields/llms-full.txt)
