Checking on Demand
Many applications check spelling when the user asks for it: a Spelling button, a menu item, or a check before a document is saved or sent. The user then walks through the misspelled words one by one in a dialog, choosing a suggestion or ignoring the word each time. With TX Spell .NET for Windows Forms, that dialog opens with one line of code, for TX Text Control as well as for a RichTextBox or any other control.
Two Dialogs to Choose From
When a spell checker is connected to a TextControl, two spelling dialogs are available. Both walk through the same misspelled words; they differ in who opens them and whether you can change them:
| Dialog of TX Text Control | Dialog of TX Spell .NET | |
|---|---|---|
| Opened by | TextControl.SpellCheckDialog, or Spell Check Dialog... in the context menu | SpellCheckDialog.Show |
| Works with | TX Text Control only | TX Text Control and any other control |
| Can be customized | No, it is preconfigured | Yes: buttons, texts, font and behavior |
| Raises MisspelledWordChanging for each change | No | Yes |
Choose the dialog of TX Text Control when the preconfigured one is all you need. Choose the dialog of TX Spell .NET to change it, to check several controls in one pass, or to check a control other than TX Text Control.
Open the Dialog of TX Text Control
The SpellCheckDialog method of the TextControl steps through all misspelled words of the document: the main text first, then the headers, footers and text frames. It is available only when a spell checker is connected through the SpellChecker property, as As-You-Type Checking shows. Call it from a button or menu item:
private void buttonSpelling_Click(object sender, EventArgs e)
{
textControl1.SpellCheckDialog();
}
An overload takes the dictionary the dialog creates suggestions from. It is useful only when more than one dictionary has been added to the spell checker.
With the ribbon of TX Text Control, you don't need this code for the user to start a check. The Proofing tab, a RibbonProofingTab, holds the spelling and hyphenation buttons, next to the groups for comments and tracked changes. Apart from the button that sets the language, its proofing buttons are enabled only when the TextControl has a spell checker connected:

Open the Dialog of TX Spell .NET
The SpellCheckDialog property of the TXSpellChecker returns the dialog of TX Spell .NET, a SpellCheckDialog. To check a TextControl, pass it to Show:
private void buttonSpelling_Click(object sender, EventArgs e)
{
txSpellChecker1.SpellCheckDialog.Show(textControl1);
}
No further code is needed for TX Text Control: the dialog finds the misspelled words and applies the user's corrections to the document itself.

The dialog shows the misspelled word in its sentence, with the language of the word above it. The user picks a suggestion and clicks Change or Change All, or skips the word with Ignore Once or Ignore All. Add To Dictionary puts the word into a user dictionary, and the Suggestions Dictionary list chooses which dictionary the suggestions come from. Spell Check Dialog describes every part of it, and Customizing the Spell Check Dialog shows how to change it.
Show has four overloads:
| Overload | Checks |
|---|---|
Show(object textControl) | The TextControl you pass |
Show(object textControl, Dictionary suggestionDictionary) | The same, with suggestions from the Dictionary you pass |
Show() | The words in IncorrectWords, found by a call to Check before |
Show(Dictionary suggestionDictionary) | The same, with suggestions from the dictionary you pass |
Check a RichTextBox in the Dialog
The dialog can walk through the words of any text, but only TX Text Control applies the corrections itself. For another control, call the spell checker's Create method once, pass the text of the control to Check and open the dialog with Show(). Each time the user changes or deletes a word, the IncorrectWordChanging event fires, and your handler makes the same change in the control. Don't call Check while the dialog is open: it throws an exception.
Open the Spell Check Dialog builds this for a RichTextBox step by step and explains the handler, and the RichTextBox\SpellCheckDialog sample of the setup works the same way. Events lists what else the handler's arguments carry, such as a Cancel property that stops the change.
Control When the Dialog Closes
Two properties of the SpellCheckDialog, CloseOnFinished and ShowMessageBoxes, decide whether the dialog closes and what it tells the user when the last word is handled; Decide How a Check Ends describes them. To check several controls in one dialog, keep it open in the SpellCheckDialogClosing event, as Checking Multiple Controls shows.
Next Steps
- Checking Multiple Controls: walk through several editors with one dialog.
- Checking Text Parts: check only the headers, footers or text frames you choose.
- Customizing the Spell Check Dialog: add, remove and rename buttons.
- Events: react to every change the dialog makes.