# As-You-Type Checking

> Underline misspelled words as users type in a Windows Forms TextControl: SpellChecker and IsSpellCheckingEnabled in the designer or code, and the context menu.

- **Product:** TX Spell .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for Windows Forms > Spell Checking > As-You-Type Checking
- **1880 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/as-you-type/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/as-you-type/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/as-you-type/llms-full.txt

---

When TX Spell .NET for Windows Forms is connected to TX Text Control, misspelled words get a red zigzag line while the user types, and a right-click on one of them offers suggestions. The connection is one property in the designer; everything after that happens without code. For a `TextBox` or `RichTextBox`, which have no underlining of their own, you check the text when it changes and mark the words yourself.

### How As-You-Type Checking Works

The editor, not the spell checker, drives checking as you type. A [TXSpellChecker](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/llms-full.txt) on the form holds the dictionaries. The `TextControl` of TX Text Control asks it about each word the user completes and underlines the words it reports as misspelled. Two properties of the `TextControl` switch this on:

- **[SpellChecker](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/spellchecker-property/llms-full.txt)** names the spell checker the editor uses. It is `null` until you connect one.
- **[IsSpellCheckingEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/isspellcheckingenabled-property/llms-full.txt)** turns checking on and off. When it is `true` and a spell checker is connected, misspelled words are underlined automatically.

Since version 29.0 of TX Text Control, a word is checked once it is complete: when the user types a delimiter such as a space, moves the caret elsewhere, or leaves the document. A word the user is still typing is not underlined. The two recordings below show the difference, before and after that change:

![A word underlined while it is still being typed, as in versions before 29.0.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/underline-while-typing.e0b00525.webp)

![A word underlined only after the space that completes it, as in version 29.0 and later.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/underline-after-word.6a8d12f4.webp)

You don't call [Create](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/create-method/llms-full.txt) on a spell checker connected to a `TextControl`: the connection initializes it.

### Connect the Spell Checker in the Designer

This needs a form with a `TextControl` and a `TXSpellChecker` on it, both from the Visual Studio toolbox. The spell checker is a component, so it appears as *txSpellChecker1* in the component tray below the form. [Getting Started](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/tx-text-control/first-application/llms-full.txt) builds this form step by step.

1. Select the `TextControl` on the form.
2. In the **Properties** window, open the drop-down of **SpellChecker** and choose **txSpellChecker1**.

    ![The SpellChecker property of a TextControl in the Properties window, with txSpellChecker1 selected in its drop-down.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/properties-spellchecker-fx.ce30bf88.webp)
3. Set **IsSpellCheckingEnabled** to **True**.
4. Run the application and type a sentence with a spelling mistake.

The spell checker's [Language](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/language-property/llms-full.txt) is "(Auto)" by default: it loads the dictionary that matches the language of the application environment, and falls back to the English "en\_US" dictionary when the dictionary folder has none that matches. The English dictionary is installed with TX Spell .NET, so English text is checked without any further setup. [Dictionaries and Languages](https://docs.textcontrol.com/tx-spell-dotnet-winforms/dictionaries/llms-full.txt) adds other languages.

### Connect It in Code

The same two properties can be set in code, for example in the form's constructor. This form has a `TextControl` called `textControl1` and creates its spell checker itself:

```csharp
using System.Windows.Forms;
using TXTextControl.Proofing;

public partial class Form1 : Form
{
    private readonly TXSpellChecker txSpellChecker1 = new TXSpellChecker();

    public Form1()
    {
        InitializeComponent();

        // Connect the spell checker and underline misspelled words as the user types
        textControl1.SpellChecker = txSpellChecker1;
        textControl1.IsSpellCheckingEnabled = true;
    }
}
```

The code works as follows:

- `new TXSpellChecker()` creates the component that a toolbox drag would otherwise create.
- `SpellChecker` connects it to the editor. Set it to `null` to disconnect the spell checker again.
- `IsSpellCheckingEnabled` starts checking. Setting it to `false` removes the underlines without disconnecting anything, which is how a "Check spelling as you type" option in your application can work.

### What the User Sees

Every misspelled word in the main text, in headers and footers and in text frames is underlined with a red zigzag line. A right-click on one opens the spell check context menu that TX Text Control shows when a spell checker is connected, with the suggestions, **Ignore**, **Ignore All**, **Add To Dictionary** and the two dialogs:

![A TextControl with misspelled words in the header and the main text, and the context menu of the word "sampke" with five suggestions, Ignore, Ignore All, Add To Dictionary, Spell Check Dialog and Options.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/textcontrol-context-menu.5b60b5a7.webp)

[Context Menus](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/context-menus/llms-full.txt) describes what each item does and how to build a menu of your own.

### Control What Is Checked and Shown

A few properties of TX Text Control decide what is underlined and which menu opens:

| Property | Effect |
|---|---|
| [TextControl.SpellCheckContextMenuStrip](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/spellcheckcontextmenustrip-property/llms-full.txt) | The menu of a right-click on a misspelled word; [Choose Which Menu Appears](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/context-menus/#choose-which-menu-appears) lists its values |
| [TextField.IsSpellCheckingEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textfield/isspellcheckingenabled-property/llms-full.txt) | Whether the text of a text field is checked. The default is `true`; set it to `false` for fields such as product codes |
| [MisspelledWord.IsIgnored](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/isignored-property/llms-full.txt) | An ignored word stays in the list of misspelled words, but is not underlined |

No property changes the color or the style of the underline.

### Check a RichTextBox as the User Types

A `RichTextBox` has no underline for misspelled words, but it can color them. Call the spell checker's [Create](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/create-method/llms-full.txt) method once, because no `TextControl` initializes it, then pass the text to [Check](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/check-method/llms-full.txt) in the `TextChanged` event and color every word in [IncorrectWords](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/incorrectwords-property/llms-full.txt) red. Unlike TX Text Control, this marks a word while it is still being typed. [Check Spelling as You Type](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/richtextbox/as-you-type/llms-full.txt) builds this application step by step.

### Check a TextBox When It Loses the Focus

For a single-line `TextBox`, checking once the user is done is often enough: check its text in the `Validating` event and report the result. [Check a TextBox When It Loses the Focus](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/richtextbox/as-you-type/#check-a-textbox-when-it-loses-the-focus) shows the handler, and [RichTextBox and TextBox](https://docs.textcontrol.com/tx-spell-dotnet-winforms/integration/richtextbox/#mark-misspelled-words-as-the-user-types) keeps the user in the field until the text is correct. [Incorrect Words and Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/suggestions/llms-full.txt) goes further with the words `Check` finds.

### Next Steps

- [Checking on Demand](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/on-demand/llms-full.txt): start a check from a button and walk through the words in the spell check dialog.
- [Incorrect Words and Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/suggestions/llms-full.txt): read the misspelled words and their suggestions in code.
- [Ignore Settings](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/ignore-settings/llms-full.txt): skip words in capitals, with numbers, URLs and e-mail addresses.
- [Checking Multiple Controls](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/multiple-controls/llms-full.txt): share one spell checker between several editors.

---

## Nearby

- **Previous:** [Spell Checking](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/llms-full.txt)
- **Next:** [Checking on Demand](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/on-demand/llms-full.txt)
