TXSpellChecker
TXSpellChecker is the component of TX Spell .NET for Windows Forms that you put on a form. It checks the text of a TX Text Control editor as the user types, checks the text of other controls on request, and brings the spell check dialog, the options dialog and the items of the spell check context menu. What follows describes what it does, how it connects to your controls and which members you use most.
What TXSpellChecker Is
The class is TXTextControl.Proofing.TXSpellChecker, derived from System.ComponentModel.Component. It has no user interface of its own: dropped on a form, it appears as txSpellChecker1 in the component tray below the form, and its dialogs and menus open only when a user or your code asks for them.
It comes with the NuGet package TXTextControl.TXSpell.WinForms.SDK, in the assembly TXSpell.Windows.Forms.dll. The package adds it to the Visual Studio toolbox, on the tab TXSpell 11.0, and brings the US English dictionary, hyphenation list and thesaurus with it.
What You Do With It
- Check TX Text Control as the user types. Connected to a
TextControl, it underlines misspelled words with a red zigzag line and offers corrections in the context menu. As-You-Type Checking - Check any other control. Check finds the misspelled words of a text, such as the text of a
RichTextBoxor aTextBox. Checking on Demand - Walk the user through the misspelled words. Its spell check dialog and options dialog are built in. Spell Check Dialog and Options Dialog
- Offer suggestions. For a context menu of your own, a list or a dialog. Context Menu and Suggestion Controls
- Hyphenate, look up synonyms and detect languages, with the same language data. Hyphenation, Language Detection
One TXSpellChecker serves every control of a form: the dictionaries are loaded once, and a word the user adds to a user dictionary counts in all editors. Checking Multiple Controls shows how.
How You Connect It
To TX Text Control, the spell checker connects through the SpellChecker property of the TextControl, in the designer or in code, and then initializes itself; the underlines, the context menu and the corrections work without further code. As-You-Type Checking shows both ways.
A RichTextBox, a TextBox or any other control doesn't talk to the spell checker itself: your code calls Create once, passes the text to Check and applies the corrections in the IncorrectWordChanging event. RichTextBox and TextBox describes this integration.
Example
This form has a TextControl and a Spelling... button. The spell checker underlines misspelled words and hyphenates the text as the user types, and the button opens the spell check dialog. It creates its controls in code, so it runs in a new Windows Forms project with the TX Text Control and TX Spell .NET packages:
using System;
using System.Windows.Forms;
using TXTextControl;
using TXTextControl.Proofing;
public class Form1 : Form
{
private readonly TextControl textControl1 = new TextControl();
private readonly TXSpellChecker txSpellChecker1 = new TXSpellChecker();
private readonly System.Windows.Forms.Button buttonSpelling = new System.Windows.Forms.Button();
public Form1()
{
textControl1.Dock = DockStyle.Fill;
buttonSpelling.Dock = DockStyle.Bottom;
buttonSpelling.Text = "Spelling...";
Controls.Add(textControl1);
Controls.Add(buttonSpelling);
// Connect the spell checker: misspelled words are underlined as the user types
textControl1.SpellChecker = txSpellChecker1;
textControl1.IsSpellCheckingEnabled = true;
textControl1.IsHyphenationEnabled = true;
// Open the spell check dialog of TX Spell .NET for this TextControl
buttonSpelling.Click += (sender, e) => txSpellChecker1.SpellCheckDialog.Show(textControl1);
}
[]
private static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
The code works as follows:
System.Windows.Forms.Buttonis written in full because theTXTextControlnamespace has aButtonclass, too.SpellChecker,IsSpellCheckingEnabledand IsHyphenationEnabled connect the spell checker and switch on checking and hyphenation.- SpellCheckDialog returns the spell check dialog;
Showopens it for theTextControl.
Create Your First Windows Forms Application builds the same application in the designer, step by step.
Key Members
| Group | Members | Purpose |
|---|---|---|
| Checking | Check, IncorrectWords, IgnoreWord, IgnoreCase | Find misspelled words, and choose which words are skipped |
| Suggestions | CreateSuggestions, Suggestions | Create the corrections for a word |
| Dictionaries | Dictionaries, Language, AvailableDictionaries | Load dictionaries and user dictionaries, and choose the default one |
| Hyphenation | GetHyphenationPoints, HyphenationLists, HyphenationLanguage | Hyphenate words |
| Synonyms | CreateSynonyms, SynonymLists | Look up synonyms |
| Language detection | DetectLanguageScopes, DetectableLanguageScopes | Find out in which language a text is written |
| User interface | SpellCheckDialog, OptionsDialog, GetMenuItems, SpellingCorrectionUIProvider | Open the dialogs, build menus and correction panels |
| Events | IncorrectWordChanging, MisspelledWordChanging, SpellCheckDialogClosing, UserDictionaryWordAdded | React to corrections, the dialog and the dictionaries |
| Language data folders | DictionariesDirectoryPath, HyphenationListsDirectoryPath, SynonymListsDirectoryPath, LanguageRecognitionDirectoryPath | Read the language data from other folders than the defaults |
Events lists all events, and the TXSpellChecker reference all members.
Next Steps
- Create Your First Windows Forms Application: a word processor with spell checking.
- TXSpell: the same checks without a user interface.
- Spell Check Dialog and Options Dialog: the dialogs of the component.
- Loading and Managing Dictionaries: other languages and user dictionaries.