How to spell check a TextBox or RichTextBox
Many applications let their users enter text via a TextBox or RichTextBox on a form. If this is how your application works, you can add a spell checker in minutes using these simple steps:
Set the Hide Selection property of the control to False. This lets Sentry Spell Checker highlight any misspelled words found.
Add a "Spell check" button or menu item to your form.
In the event handler for your "Spell check" button or menu item, invoke the CheckCtrlDlg method of the SpellingCheckerEngine class, passing the Handle property of the text box you want to check.
That's all there is to it! When the "Spell check" button or menu item is pressed, Sentry will check the spelling of words in the control. If a misspelled word is found, Sentry will pop up a dialog the user can interact with to dispose of the misspelling. The misspelled word will be highlighted in the TextBox or RichTextBox. The dialog shows suggested replacements for the misspelled word. If the user makes a correction, the control will be updated automatically.
How to check spelling "as you type"
You may want to give your users immediate feedback on spelling errors, to report misspellings as soon as they occur. This feature is used in Microsoft Office. Your users are probably already familiar with the "as you type" spell checker feature and may demand it in your product. Including it will give your product a competitive advantage.
"As you type" spell checking is easy with Sentry! Just handle the TextChanged and SelectionChanged events from the control, and call Sentry's CheckCtrlBackgroundNotify method. Sentry will monitor the user's typing in the background, and will mark any misspelled words (e.g., by changing the text color to red). Corrected words are automatically unmarked. You can catch right-mouse clicks and display a spelling context menu by calling the CheckCtrlBackgroundMenu method.
How to spell check strings
The text you want to spell check may not be entered by the user -- it may be read from a disk file or database, or obtained from data structures within your application.
Sentry Spell Checker can check words contained in strings, including the StringBuilder type, interactively or not interactively.
To check a StringBuilder object interactively, just pass it to the CheckBlockDlg method. The StringBuilder can contain a single word or an entire book. Sentry will check the spelling of words in the string. If a misspelled word is found, Sentry will pop up a dialog the user can interact with to dispose of the problem. The dialog shows suggested replacements for the misspelled word. If the user makes a correction, the StringBuilder object will be updated automatically. Sentry can even optionally show the StringBuilder's contents in a text box attached to the dialog so the user can see the misspelled words in context.
Checking strings non-interactively is done via the CheckString method. CheckString is usually called in a loop. It checks each word in the string and returns when it finds a misspelled word or when all words have been checked. Your application can obtain a list of suggested replacements for the misspelled word from the Suggest function.