TX Spell .NET for Windows Forms

Checking on Demand

Topic

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 ControlDialog of TX Spell .NET
Opened byTextControl.SpellCheckDialog, or Spell Check Dialog... in the context menuSpellCheckDialog.Show
Works withTX Text Control onlyTX Text Control and any other control
Can be customizedNo, it is preconfiguredYes: buttons, texts, font and behavior
Raises MisspelledWordChanging for each changeNoYes

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:

The Proofing tab of the ribbon in TX Text Control Words, with Enable Spell Checking, Enable Hyphenations, Thesaurus and Spelling in the Spelling & Hyphenation group.

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 Spelling dialog over a TextControl: the sentence with the misspelled word "sampke" in red, the suggestions sample, spake and smoke, the buttons Ignore Once, Ignore All, Add To Dictionary, Change and Change All, the Suggestions Dictionary en_US.dic, Options and Cancel.

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:

OverloadChecks
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