Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Collapse]Spell Checker
   [Expand]Product Information
   [Collapse]Getting Started
     Lesson 1 - Add Spell Checking to Your Application
     Lesson 2 - Create Simple Application to Check Spelling in MemoEdit
   [Expand]Fundamentals
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Lesson 2 - Create Simple Application to Check Spelling in MemoEdit

This tutorial demonstrates how to use the SpellChecker component to check spelling in DevExpress MemoEdit control using German dictionaries.

The SpellChecker component can check the spelling of a wide range of text-aware controls. For more information, refer to Supported Controls.

To create an application, follow the steps below:

Expanded Step 1. Add a SpellChecker Component and the MemoEdit Contol

  1. Add the SpellChecker component to your project. To do this, simply drag the corresponding item from the DX.17.1: Components toolbox tab, and drop it onto the form.

    Note

    The SharedDictionaryStorage component item, situated in the toolbox near the SpellChecker component, may be added to the project, if it is necessary to have several dictionaries available for different instances of the SpellChecker component.

  2. Specify the default language (German) of the spell checker. For this, set SpellCheckerBase.Culture property to de-DE using the Property editor:

  3. Add the MemoEdit control (located on the DX.17.1: Common Controls toolbox tab) to the form and open the Properties window for it (e.g. by pressing F4). Since the control's content can be checked by the SpellChecker component, a number of extender properties appears when it is dropped on the form containing the SpellChecker.

    For now, you may leave these settings as is, and go to the next step.

Expanded Step 2. Add Dictionaries

The next step is specifying the dictionaries.

Currently there are four types of dictionaries:

For detailed information on dictionaries, see Dictionaries.

For each dictionary, you should specify its DictionaryBase.Culture and SpellCheckerDictionaryBase.Encoding. Complex dictionaries, such as ISpell, OpenOffice or Hunspell types, require an affix file, located in the path specified by the GrammarPath property. The need for the alphabet file is due to the method for generating the suggestion lists. For more details, please refer to the SpellCheckerDictionaryBase.AlphabetPath topic.

In this example, an OpenOffice dictionary and a custom dictionary will be used. You can find them at the Dictionaries page of the OpenOffice.org project. Download the German dictionaries extension form the extension repository. Change file extension to zip and unzip it with any archiver. Extract the de_DE.dic and de_DE.aff files to a temporary folder.

  1. Create the Dictionaries folder in the directory of your project and copy the required dictionary files (de_DE.dic and de_DE.aff) to it.
  2. Create a new text file in the Dictionaries folder and name it GermanAlphabet.txt. This file will contain German letters in the order required for proper sorting. Copy the following string to that file:

    AÄBCDEFGHIJKLMNOÖPQRSßTUÜVWXYZ

  3. Create a new empty text file in the Dictionaries folder and name it CustomGermanDictionary.txt. This file will contain words added to a custom dictionary.
  4. Include the Dictionaries folder in the project.
  5. Note

    If the Dictionaries folder is not displayed in the Solution Explorer, select Show All Files from the Project menu or click Show All Files on the Solution Explorer toolbar.

  6. Set the Copy to Output Directory property to Copy always for each file in the Dictionaries folder except the CustomGermanDictionary.txt. For the CustomGermanDictionary.txt specify Copy if newer.
  7. Open the Properties window for the SpellChecker component, and click the Dictionaries item. The ISpellCheckerDictionary Collection Editor window will be invoked.
  8. In this window, click the Add arrow, and select SpellCheckerOpenOfficeDictionary to add the OpenOffice dictionary.
  9. Specify the dictionary properties as follows:

    • Culture - de-DE
    • DictionaryPath - Dictionaries\de_DE.dic
    • Encoding - Western European (Windows)
    • GrammarPath - Dictionaries\de_DE.aff

  10. To add the custom dictionary, click the Add arrow and select the SpellCheckerCustomDictionary item.
  11. Specify the dictionary properties as follows:

    • AlphabetPath - Dictionaries\GermanAlphabet.txt
    • Culture - de-DE
    • DictionaryPath - Dictionaries\CustomGermanDictionary.txt
    • Encoding - Western European (Windows)

Now, decide whether SpellChecker will start spell check on demand (for example, when clicking a button), or it will check spelling as you type.

Expanded Step 3. Check Spelling On Demand

To start checking the spelling in the MemoEdit control when clicking the button:

  1. Set the SpellCheckMode property of SpellChecker to OnDemand.
  2. Add the SimpleButton control (located on the DX.17.1: Common Controls toolbox tab) to the form.
  3. To start spell checking in the MemoEdit control and invoke the Spelling dialog to make corrections when you click the button, use the following code:

    When this method is called at runtime, the SpellChecker component loads the dictionaries, if they are not already loaded, and starts spell checking the MemoEdit control's content.

    Note

    You may use the SpellChecker.SetShowSpellCheckMenu method to show the Check Spelling item in the MemoEdit control's context menu.

Expanded Step 4. Check Spelling As You Type

To enable SpellChecker to check the spelling of the MemoEditor control as you type:

  1. Set the SpellCheckMode property of SpellChecker to AsYouType.
  2. To perform spell check as you type, use the following code:

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E2413.

    This underlines the misspelled word when the end-user finishes typing the word or moves the cursor after changing it, and allows selecting a suggestion from the context menu, invoked by right-clicking the word.

Expanded Step 5. User Interaction

When SpellChecker encounters a word that is not found within available dictionaries, or a duplicated word, the Spelling dialog can be used for making corrections. It is invoked, when the end-user starts checking spelling on demand (calls the SpellChecker.Check method), or selects the Check Spelling item from the context menu.

Generally, the Spelling dialog of the SpellingFormType.Outlook type will best suit the user.

You can, however, change it to the more versatile SpellingFormType.Word, shown in the picture below, via the SpellCheckerBase.SpellingFormType property.

In this dialog, the end-user can replace the current occurrence or all occurrences of the misspelled word with one of the suggested corrections, ignore this word once or all its occurrences, or add the word to the dictionary of the SpellChecker.

The Options... button enables the end-user to change the spelling options or the language dictionary to be used, and provides access to the custom dictionary editor. The Undo button can cancel the changes, step by step.

How would you rate this topic?​​​​​​​