TX Spell .NET for Windows Forms

Spell Check Dialog

Topic

The Spelling dialog of TX Spell .NET walks the user through the misspelled words of a document, one word at a time: it shows the word in its sentence, lists suggestions and offers to change, ignore or learn the word. Each part of the dialog is described below, together with what each button does and how to decide where the dialog opens and how a check ends.

Which Dialog This Is

A TextControl with a connected spell checker offers two spelling dialogs. TX Text Control opens its own preconfigured dialog from the Spell Check Dialog... item of its context menu. The dialog described here is the one of TX Spell .NET, a SpellCheckDialog that you get from the SpellCheckDialog property of the TXSpellChecker. It checks a TextControl as well as a RichTextBox, a TextBox or any other control, and you can change its buttons, texts and behavior.

Both dialogs look alike to the user. Checking on Demand compares them and shows when to choose which.

The Parts of the Dialog

The dialog has the title Spelling. Its parts are numbered in the picture below and described in the table after it:

The Spelling dialog with numbered parts: 1 the line "Misspelled word - Language: English (United States)", 2 the sentence with the misspelled word "sampke" in red, 3 the buttons Ignore Once, Ignore All and Add To Dictionary, 4 the list of suggestions, 5 the buttons Change and Change All, 6 the Suggestions Dictionary list with en_US.dic, 7 the Options button and 8 the Cancel button.

PartWhat it shows or does
1Misspelled word - LanguageThe language of the word. For text without language information, such as the text of a RichTextBox, it reads "No language set"
2PreviewThe sentence that contains the misspelled word, with the word in red. The user can edit the sentence here
3Ignore Once, Ignore All, Add To DictionarySkip the word, skip it everywhere, or add it to a user dictionary
4SuggestionsThe words that could be meant, at most 10 by default
5Change, Change AllReplace the word with the selected suggestion, here or everywhere
6Suggestions DictionaryThe dictionary the suggestions come from
7Options...Opens the Options Dialog
8CancelCloses the dialog before the check is complete

The three groups of buttons at 3, 5 and 7 are collections of the SpellCheckDialog: IgnoreButtons, ChangeButtons and OptionButtons. The preview at 2 is described by Preview, the list at 4 by SuggestionList and the list at 6 by SuggestionDictionaryComboBox. Customizing the Spell Check Dialog changes the buttons and the preview, and Suggestion Controls the two lists.

What Each Button Does

Each button of the dialog has a type, a value of TXSpell.ButtonType, that decides what a click does:

ButtonTypeWhat happens
Ignore OnceIgnoreThe word is skipped at this place only
Ignore AllIgnoreAllEvery occurrence of the word is skipped
Add To DictionaryAddToDictionaryThe word is added to the user dictionaries and is no longer marked
ChangeChangeThe word is replaced with the selected suggestion
Change AllChangeAllEvery occurrence of the word is replaced with the selected suggestion
Options...OptionsThe options dialog opens

Add To Dictionary is enabled only when a user dictionary has been added to the dictionaries of the spell checker; in the picture, none has. User Dictionaries shows how to add one.

Two more types change a button while the dialog is open:

  • Delete replaces a button when the current word repeats the word before it, as in "the the". It removes the repeated word. A button becomes a Delete button when its IsDeleteButton property is true.
  • Undo Edit replaces a button as soon as the user edits the sentence in the preview. It discards the edit. A button becomes an Undo Edit button when its IsUndoEditButton property is true; when no button has it set, the preview can't be edited.

When the user presses Enter, the dialog clicks its AcceptButton, which is Ignore Once by default.

Open the Dialog

Show opens the dialog: with a TextControl, which the dialog corrects itself, or without arguments for the words a call of Check found in any other text. Checking on Demand shows both ways and the overloads of Show.

What the Dialog Checks

For a TextControl, the dialog checks the main text and then the headers, footers and text frames, and ChangeInAllTextParts and IgnoreInAllTextParts decide whether Change All and Ignore All reach into the other parts; Checking Text Parts describes both. The dialog can also continue from one control to the next, so that the user checks a whole form in one pass, as Checking Multiple Controls shows.

Choose Where the Dialog Opens

By default, the dialog opens in the center of the screen. ShowDialogSettings sets its owner and its start position. Set them once, for example in the constructor of the form, after InitializeComponent:

using TXTextControl.Proofing;

// Center the dialog on this form instead of the screen
txSpellChecker1.SpellCheckDialog.ShowDialogSettings.Owner = this;
txSpellChecker1.SpellCheckDialog.ShowDialogSettings.StartPosition = TXSpell.DialogStartPosition.CenterOwner;

The code works as follows:

To open the dialog where the user left it, read the Location of the SpellCheckDialog after it closes. It holds the last position of the dialog's upper-left corner, and Point.Empty before the dialog was shown for the first time.

Decide How a Check Ends

Two properties of the SpellCheckDialog decide what the user sees when the last word is handled:

PropertyDefaultEffect
CloseOnFinishedtrueThe dialog closes when the check is complete
ShowMessageBoxestrueMessage boxes tell the user that the check is complete, or that a word the user typed is not in the suggestion dictionary

Set ShowMessageBoxes to false to report the result in your own way, for example in a status bar.

The SpellCheckDialogOpening and SpellCheckDialogClosing events of the TXSpellChecker fire when the dialog opens and closes. Events shows what their arguments carry.

The Dialog on High-Resolution Screens

Since version 8.0, the spell check dialog and the options dialog scale with the display, also on setups with several monitors of different scale factors; High DPI and Display Scaling describes the setting.

Next Steps