# Spell Checking and Hyphenation

> Connect TX Spell .NET to a Windows Forms TextControl, use SpellCheckText for another checker, ignore MisspelledWords in code and control HyphenateWord.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Document Editor > Spell Checking and Hyphenation
- **3035 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/spell-checking/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/spell-checking/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/spell-checking/llms-full.txt

---

The `TextControl` underlines misspelled words, offers corrections in a context menu and a dialog box, and hyphenates words at the end of a line, but it doesn't contain dictionaries of its own. The words come from a spell checker you connect: TX Spell .NET for Windows Forms, a separate product of Text Control, or a checker of your own through an event. What follows shows what each side contributes, how the two are connected and where the TX Spell .NET documentation continues.

The examples belong in *Form1.cs* of an application with a `TextControl` named `textControl1`, like the one of [Create Your First Windows Forms Application](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-editor/first-application/llms-full.txt).

### What the User Sees

With a spell checker connected and spell checking turned on, misspelled words get a red zigzag underline while the user types. A right-click on such a word opens a context menu with suggestions and the commands **Ignore**, **Ignore All**, **Add To Dictionary**, **Spell Check Dialog...** and **Options...**:

![A Windows Forms TextControl with misspelled words underlined in red, in the header and the main text, and the spell check context menu open with the suggestions sample, spake, smoke, samples and sampler.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/spell-check-context-menu.5b60b5a7.webp)

The **Proofing** tab of the ribbon, the [RibbonProofingTab](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-windows-forms-ribbon/ribbonproofingtab/llms-full.txt), has a **Spelling & Hyphenation** group with the buttons **Enable Spell Checking**, **Enable Hyphenations**, **Thesaurus** and **Spelling**, which opens the spelling dialog. Most buttons of the tab are enabled only while a spell checker is connected.

![The Proofing tab of TX Text Control Words with the groups Spelling & Hyphenation, Settings, Track Changes and the Language button, over a document with a misspelled word.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/ribbon-proofing-tab.748b5cc8.webp)

The spelling dialog shows the misspelled word in its sentence, the language, the suggestions of the selected dictionary and the buttons **Ignore Once**, **Ignore All**, **Add To Dictionary**, **Change**, **Change All** and **Options...**:

![The Spelling dialog box over a TextControl, with the misspelled word sampke in red, the suggestions sample, spake and smoke, the suggestions dictionary en_US.dic and the buttons to ignore, add and change the word.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/spelling-dialog.1c62f1f3.webp)

### What TX Text Control Provides

The `TextControl` has the properties, methods and events that a spell checker works through:

| Member | Purpose |
|---|---|
| [SpellChecker](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/spellchecker-property/llms-full.txt) | Connects the spell checker, a `TXSpellChecker` of TX Spell .NET |
| [IsSpellCheckingEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/isspellcheckingenabled-property/llms-full.txt) | Turns checking as the user types on or off |
| [SpellCheckDialog](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/spellcheckdialog-method/llms-full.txt) | Opens the built-in spelling dialog, which steps through the main text, headers, footers and text frames |
| [SpellCheckContextMenuStrip](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/spellcheckcontextmenustrip-property/llms-full.txt) | The context menu of a misspelled word: `(Default)` for the built-in menu, `(none)` for no menu, or the name of your own `ContextMenuStrip` |
| [MisspelledWords](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/misspelledwords-property/llms-full.txt) | The misspelled words of the text part with the input focus, as [MisspelledWord](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/llms-full.txt) objects |
| [IsHyphenationEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/ishyphenationenabled-property/llms-full.txt) | Divides the last word of a line with a hyphen |
| [HyphenateWord](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/hyphenateword-event/llms-full.txt) | Occurs for every word to hyphenate; the handler can change where it is divided |
| [IsLanguageDetectionEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/islanguagedetectionenabled-property/llms-full.txt) | Sets a language for text without one, detected by TX Spell .NET |
| [LanguageDialog](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/languagedialog-method/llms-full.txt) | Opens the dialog box that sets the language of the selected text, which decides the dictionary |
| [SpellCheckText](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/spellchecktext-event/llms-full.txt) | Passes new text to your own spell checker when no `SpellChecker` is connected |

### Connect TX Spell .NET

TX Spell .NET for Windows Forms is installed, licensed and deployed separately. Its `TXSpellChecker` component is connected to the editor with the `SpellChecker` property, in the **Properties** window or in code:

```csharp
textControl1.SpellChecker = txSpellChecker1;
textControl1.IsSpellCheckingEnabled = true;
```

[Integrating TX Spell .NET for Windows Forms](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/integration/tx-spell/llms-full.txt) walks through the package, the licenses, the connection, several editors and deployment, and lists the pages of the TX Spell .NET documentation that continue from there.

### Use Another Spell Checker

Without a connected `SpellChecker`, the `TextControl` raises [SpellCheckText](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/spellchecktext-event/llms-full.txt) whenever text has changed and `IsSpellCheckingEnabled` is `true`. The handler checks the text and reports the misspelled words, which the editor then underlines. The following handler marks every occurrence of the misspelling *teh*:

```csharp
private void textControl1_SpellCheckText(object sender, SpellCheckTextEventArgs e)
{
    List<MisspelledWord> misspelledWords = new List<MisspelledWord>();

    // Find the words with your spell checker; here, one known typo
    int index = e.Text.IndexOf("teh");

    while (index >= 0)
    {
        // MisspelledWord positions are one-based
        misspelledWords.Add(new MisspelledWord(index + 1, 3));
        index = e.Text.IndexOf("teh", index + 3);
    }

    e.MisspelledWords = misspelledWords.ToArray();
}
```

The code works as follows:

- [SpellCheckTextEventArgs.Text](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/spellchecktexteventargs/text-property/llms-full.txt) is the text to check, and [Culture](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/spellchecktexteventargs/culture-property/llms-full.txt) its language, for choosing a dictionary.
- A [MisspelledWord](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/constructor/llms-full.txt) is created with the one-based start of the word in `Text` and its length.
- [MisspelledWords](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/spellchecktexteventargs/misspelledwords-property/llms-full.txt) returns the result to the editor.

Connect the handler on the **Events** page of the **Properties** window, set `IsSpellCheckingEnabled` to `true`, and `List<T>` needs `using System.Collections.Generic;`. The dialog box and the context menu with suggestions of TX Text Control need a connected `SpellChecker`; with your own checker, you provide them yourself.

### List and Ignore Misspelled Words

Whichever checker finds them, the misspelled words of the text part with the input focus are in a [MisspelledWordCollection](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledwordcollection/llms-full.txt), which `TextControl.MisspelledWords` returns. Your code can go through them, for example to show a list of errors in a panel, and ignore or correct them without a dialog box:

```csharp
private void ignoreProductNamesButton_Click(object sender, EventArgs e)
{
    foreach (MisspelledWord word in textControl1.MisspelledWords)
    {
        if (word.Text == "TXTextControl")
        {
            // Keep the text, but don't underline it any longer
            word.IsIgnored = true;
        }
    }

    // Jump to the next misspelled word after the input position and select it
    MisspelledWord next = textControl1.MisspelledWords.GetItem();
    next?.Select();
}
```

- Each [MisspelledWord](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/llms-full.txt) has its [Text](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/text-property/llms-full.txt), its one-based [Start](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/start-property/llms-full.txt), its [Length](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/length-property/llms-full.txt) and its [Culture](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/culture-property/llms-full.txt). [IsDuplicate](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/isduplicate-property/llms-full.txt) marks a correctly spelled word that repeats the word in front of it.
- [IsIgnored](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/isignored-property/llms-full.txt) keeps a word in the collection but removes its red zigzag line. [MisspelledWordCollection.Ignore](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledwordcollection/ignore-method/llms-full.txt) replaces the text of a word and marks it as ignored in one call.
- [MisspelledWordCollection.Remove](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledwordcollection/remove-method/llms-full.txt) takes a word out of the collection and, with a second parameter, replaces its text with the corrected text.
- [MisspelledWordCollection.GetItem](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledwordcollection/getitem-method/llms-full.txt) without a parameter returns the misspelled word at or after the input position; other overloads take a text position, a point in pixels under the mouse pointer or a [MisspelledWordKind](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledwordkind/enumeration/llms-full.txt). [Select](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/select-method/llms-full.txt) selects the word in the text.

While the user edits a header, a footer or a text frame, the collection holds the misspelled words of that part; each of them also has a `MisspelledWords` collection of its own.

### Control Where Words Are Divided

[HyphenateWord](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/hyphenateword-event/llms-full.txt) occurs when `IsHyphenationEnabled` is `true` and a word doesn't fit into the line. Its [HyphenateWordEventArgs](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/hyphenatewordeventargs/llms-full.txt) carry the [Word](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/hyphenatewordeventargs/word-property/llms-full.txt), its [Culture](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/hyphenatewordeventargs/culture-property/llms-full.txt), the [DividePos](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/hyphenatewordeventargs/dividepos-property/llms-full.txt) that TX Spell .NET calculated, or 0 without a spell checker, and the [MaxDividePos](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/hyphenatewordeventargs/maxdividepos-property/llms-full.txt), the number of characters that still fit into the line. The editor divides the word at `DividePos` if it isn't greater than `MaxDividePos`. The following handler keeps short words together:

```csharp
private void textControl1_HyphenateWord(object sender, HyphenateWordEventArgs e)
{
    // Don't divide words of fewer than seven characters
    if (e.Word.Length < 7)
    {
        e.DividePos = 0;
    }
}
```

### Next Steps

- [TX Spell .NET for Windows Forms](https://docs.textcontrol.com/tx-spell-dotnet-winforms/llms-full.txt): the documentation of the spell checker.
- [Built-in Ribbon Tabs](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/ribbon/llms-full.txt): the **Proofing** tab and the other tabs of the ribbon.
- [Context Menus](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/context-menus/llms-full.txt): the other context menus of the editor.
- [Events](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/events/llms-full.txt): connect handlers such as `SpellCheckText`.

---

## Nearby

- **Previous:** [Document Protection and Editable Regions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/protection/llms-full.txt)
- **Next:** [Viewing, Zooming, and Navigation](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/viewing/llms-full.txt)
