# Open the Spell Check Dialog

> Open the spell check dialog for a Windows Forms RichTextBox with Check and SpellCheckDialog.Show, and apply corrections in the IncorrectWordChanging event.

- **Product:** TX Spell .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for Windows Forms > Getting Started > RichTextBox and TextBox > Open the Spell Check Dialog
- **1721 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/richtextbox/dialog/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/richtextbox/dialog/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/richtextbox/dialog/llms-full.txt

---

The spell check dialog of TX Spell .NET works with any control, not only with TX Text Control. For a `RichTextBox`, the dialog walks through the misspelled words and the user picks a correction, while a short event handler writes each correction back into the control. You add this to the application of [Check Spelling as You Type](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/richtextbox/as-you-type/llms-full.txt).

### Prerequisites

- The application of [Check Spelling as You Type](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/richtextbox/as-you-type/llms-full.txt): a form with a `RichTextBox` called *richTextBox1* and a `TXSpellChecker` called *txSpellChecker1*, in a project with the package `TXTextControl.TXSpell.WinForms.SDK`.

### How the Dialog Works With a RichTextBox

A `RichTextBox` knows nothing about the spell checker, so the work is split in two:

1. Your code passes the text to [Check](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/check-method/llms-full.txt). The spell checker finds the incorrect words and keeps them in [IncorrectWords](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/incorrectwords-property/llms-full.txt).
2. [Show](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/show-method/llms-full.txt) opens the dialog with these words. Each time the user changes or deletes a word, the spell checker raises [IncorrectWordChanging](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/incorrectwordchanging-event/llms-full.txt), and your handler makes the same change in the `RichTextBox`.

### Add the Button

1. Open **Form1** in the designer. Select *richTextBox1* and set its **Dock** property to **None**, so that there is room for a button, and make it a little smaller.
2. Draw a `Button` from the **Common Controls** tab onto the form. Set its **Text** to *Spell Check Dialog...* and its **(Name)** to *buttonSpelling*.
3. Double-click the button. Visual Studio creates the handler `buttonSpelling_Click`.
4. Select *txSpellChecker1* in the component tray, click the **Events** button of the **Properties** window and double-click `IncorrectWordChanging`. Visual Studio creates the handler `txSpellChecker1_IncorrectWordChanging`.

### Write the Code

Add the code to the two handlers in *Form1.cs*:

```csharp
private void buttonSpelling_Click(object sender, EventArgs e)
{
    // Find the incorrect words, then walk through them in the dialog
    txSpellChecker1.Check(richTextBox1.Text);
    txSpellChecker1.SpellCheckDialog.Show();
}

private void txSpellChecker1_IncorrectWordChanging(object sender, IncorrectWordChangingEventArgs e)
{
    // Keep the TextChanged handler from checking while the dialog is open
    isColoring = true;

    // Select the word the user is changing
    richTextBox1.Select(e.IncorrectWord.Start, e.IncorrectWord.Length);

    if (e.Type == TXSpell.ChangeType.Replace)
    {
        richTextBox1.SelectedText = e.CorrectedWord;
    }
    else if (e.Type == TXSpell.ChangeType.Delete)
    {
        richTextBox1.SelectedText = "";
    }

    isColoring = false;
}
```

#### What the Code Does

- [SpellCheckDialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/spellcheckdialog-property/llms-full.txt) returns the dialog of the spell checker. `Show()` without arguments opens it with the words of the last `Check`.
- [Type](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/incorrectwordchangingeventargs/type-property/llms-full.txt) says what the user did: `Replace`, `Delete` or `Ignore`, values of [TXSpell.ChangeType](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspell-changetype/enumeration/llms-full.txt). An ignored word needs no change in the text.
- [IncorrectWord](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/incorrectwordchangingeventargs/incorrectword-property/llms-full.txt) is the word being changed, with its position in the text.
- [CorrectedWord](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/incorrectwordchangingeventargs/correctedword-property/llms-full.txt) is the suggestion the user chose. Read it only when `Type` is `Replace`: for other types, it throws an exception.
- `isColoring` is the flag of the `TextChanged` handler from [Check Spelling as You Type](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/richtextbox/as-you-type/llms-full.txt). Changing the text raises `TextChanged`, and the handler would call `Check` while the dialog is open, which throws an exception. The flag makes the handler skip these changes; the colors are updated again when the user types.

The code uses `IncorrectWordChangingEventArgs` and `TXSpell` from the `TXTextControl.Proofing` namespace, which the `using` directive of *Form1.cs* already imports.

### Run the Application

Press **F5**, type a sentence with a few mistakes, and click **Spell Check Dialog...**. The dialog opens with the first misspelled word in its sentence:

![The Spelling dialog over a RichTextBox: the sentence with the misspelled word "sampke" in red, the language line "No language set", the suggestions sample, spake, smoke, samples, sampler and sampled, and the buttons Ignore Once, Ignore All, Add To Dictionary, Change, Change All, Options and Cancel.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/richtextbox-spelling-dialog.b515f6c9.webp)

Select a suggestion and click **Change**: the word is replaced in the `RichTextBox`, and the dialog moves on to the next one. **Ignore Once** and **Ignore All** skip words, and **Cancel** ends the check. The dialog shows "No language set" because the text of a `RichTextBox` carries no language information.

### Offer Suggestions in the Context Menu

The same words can also be corrected with a right-click. The [GetMenuItems](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/getmenuitems-method/llms-full.txt) method returns ready-made menu items for an incorrect word, with suggestions and the commands of the dialog, to put into a `ContextMenuStrip`:

![The context menu of a misspelled word in a RichTextBox, with five suggestions, Ignore, Ignore All, Add To Dictionary, Spell Check Dialog and Options.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/richtextbox-context-menu.f03e53b3.webp)

[Context Menus](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/context-menus/llms-full.txt) builds this menu step by step.

### Next Steps

- [Checking on Demand](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/on-demand/llms-full.txt): the two dialogs, and how a check ends.
- [Checking Multiple Controls](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/multiple-controls/llms-full.txt): check several `RichTextBox` controls in one dialog.
- [Events](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/events/llms-full.txt): everything the arguments of `IncorrectWordChanging` carry.

---

## Nearby

- **Previous:** [Check Spelling as You Type](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/richtextbox/as-you-type/llms-full.txt)
- **Next:** [Checking Text in Code](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/in-code/llms-full.txt)
