TX Spell .NET for Windows Forms

Product Architecture

Topic

Knowing how the parts of TX Spell .NET for Windows Forms fit together makes it easier to add it to a project and to deploy the result. The sections below describe the assemblies and classes, the language data they read, how TX Text Control and other controls use the spell checker, and what each NuGet package brings.

How the Parts Fit

 Windows Forms application
 ┌──────────────────────────────────────────────────────────────────┐
 │  TextControl ── SpellChecker ──►┐                                │
 │  RichTextBox / TextBox ─ Check ─►  TXSpellChecker                │
 │                                  (dialogs, menu items, events)   │
 │                                  TXSpell.Windows.Forms.dll       │
 │                                         │                        │
 │  Console, service, server ─────────►  TXSpell                    │
 │                                  (checking, suggestions,         │
 │                                   hyphenation, synonyms,         │
 │                                   language detection)            │
 │                                  TXSpell.dll                     │
 └─────────────────────────────────────────┬────────────────────────┘
                                           │ reads
     Dictionaries   HyphenationLists   SynonymLists   LanguageRecognition

TX Spell .NET has one engine, TXSpell.dll, shared by all its products, and one assembly with the user interface for each platform, here TXSpell.Windows.Forms.dll. Both read the language data from four folders next to the application.

The Two Classes

TXSpellCheckerTXSpell
AssemblyTXSpell.Windows.Forms.dllTXSpell.dll
NamespaceTXTextControl.ProofingTXTextControl.Proofing
What it isA component, derived from System.ComponentModel.Component, on a formA class for code
User interfaceSpell check dialog, options dialog, context menu itemsNone
EventsFor corrections, the dialog and the dictionariesNone
Connects to TX Text ControlTo the TextControl of Windows FormsOnly to ServerTextControl
InitializationAutomatic when connected to a TextControl, otherwise CreateCreate before first use
PackageTXTextControl.TXSpell.WinForms.SDKTXTextControl.TXSpell.Core.SDK, and the Windows Forms package

Both classes check text, create suggestions, hyphenate, find synonyms and detect languages with the same members, such as Check, CreateSuggestions and GetHyphenationPoints. The classes of the language data, such as OpenOfficeDictionary, UserDictionary and HyphenationList, are shared by both. Components describes each part.

The texts of the dialogs are resources: English is built in, German comes as the satellite assembly de\TXSpell.resources.dll, and Localization and Resource Kit adds other languages.

The Language Data

The spell checker reads its language data from four folders next to the application: Dictionaries for spell checking and suggestions, HyphenationLists for hyphenation, SynonymLists for synonyms and LanguageRecognition for language detection. The NuGet packages copy them with the US English data into the output directory when you build; Installing Dictionaries and Language Data describes the folders, where the spell checker looks for them and how to keep them elsewhere.

How TX Text Control Uses the Spell Checker

A TextControl gets its spell checker through its SpellChecker property. From then on, the editor drives the checking, and the spell checker answers:

  1. The user types a word. When the word is complete, the TextControl asks the spell checker whether it is spelled correctly.
  2. The TextControl underlines the misspelled words and keeps them in its MisspelledWords collection, which holds the misspelled words of the part of the document with the input focus, such as the main text, a header or a text frame.
  3. A right-click on an underlined word opens the spell check menu; the menu and the dialogs correct the word in the document.

IsSpellCheckingEnabled, IsHyphenationEnabled and IsLanguageDetectionEnabled of the TextControl switch the three services on. As-You-Type Checking describes the connection in detail.

How Other Controls Use It

A RichTextBox or a TextBox doesn't know the spell checker. Your application does the work the TextControl does by itself:

  1. It passes the text to Check, which fills IncorrectWords with the misspelled words and their positions.
  2. It marks the words, or opens the spell check dialog for them.
  3. It applies each correction the user makes in the IncorrectWordChanging event.

Checking on Demand shows these steps with a RichTextBox.

The NuGet Packages

Two NuGet packages bring the assemblies into a .NET project: TXTextControl.TXSpell.WinForms.SDK with TXSpell.dll and TXSpell.Windows.Forms.dll, and TXTextControl.TXSpell.Core.SDK with TXSpell.dll only. Both also bring the US English language data, the German texts and the license file, and neither depends on TX Text Control; Package Overview lists what each contains.

One Spell Checker for Many Controls

One TXSpellChecker serves every TextControl and every other control of a form, and of other forms. The dictionaries are loaded once, and a word the user adds to a user dictionary is accepted in all editors at once. Checking Multiple Controls shows how to share it and how one dialog checks several controls.

Next Steps