Using User Dictionaries with TX Spell .NET

A user dictionary is a separate dictionary that can be used to add custom words such as brand names, trademarks or a specific vocabulary. TX Spell .NET uses plain text word lists as a user dictionary with the specific file extension *.txd. Using TX Spell .NET, an unlimited number of dictionaries and user dictionaries can be used at the same time. If a user dictionary is added to the DictionaryCollection, the Add to dictionary... button of the spell check dialog and the context menu is enabled. Where the spell check dialog and the user dictionary manager enable users to add and remove words manually, this sample shows how to use the API to access these user dictionaries.

The source code is contained in the following directories:

  • %USERPROFILE%\My Documents\TX Spell 7.0.NET for Windows Forms\Samples\WinForms\CSharp\UserDictionary
  • %USERPROFILE%\My Documents\TX Spell 7.0.NET for Windows Forms\Samples\WinForms\VB.NET\UserDictionary

Creating a User Dictionary

The <UserDictionary constructor can be used to load an existing user dictionary from a specific path or the default dictionary path. Using only the dictionary name without any path specifications, the corresponding dictionary file inside the default dictionary folder will be used. The name of the specified user dictionary file must end in ".txd". To create a new user dictionary, no constructor may be used. The following code shows how to create a new user dictionary and how to add some custom words to it:

userDic = new TXTextControl.Proofing.UserDictionary();
txSpellChecker1.Dictionaries.Add(userDic);

userDic.Name = "User Dictionary";
userDic.AddWord("TXTextControl");
userDic.AddWord("TXSpell");
userDic = New TXTextControl.Proofing.UserDictionary()
txSpellChecker1.Dictionaries.Add(userDic)

userDic.Name = "User Dictionary"
userDic.AddWord("TXTextControl")
userDic.AddWord("TXSpell")

Every Dictionary (OpenOfficeDictionary or UserDictionary) is enabled for spell checking and for creating suggestions by default. Therefore, the Dictionary.IsSpellCheckingEnabled and Dictionary.IsGetSuggestionsEnabled properties are set to true. To disable the usage of a specific dictionary, set the Dictionary.IsSpellCheckingEnabled to false.

Adding and Removing Words from the User Dictionary

In order to edit user dictionaries, the UserDictionary.IsEditable property must be set to true. This sample consists of a simple interface to add and remove words to and from the user dictionary. A ListBox is synchronized to show the content of the user dictionary. The following code is used to add a word to the user dictionary using the UserDictionary.AddWord method.

userDic.AddWord(tbNewWord.Text);
userDic.AddWord(tbNewWord.Text)

To remove a word from the user dictionary, the UserDictionary.RemoveWord method is used:

userDic.RemoveWord(listBox1.Text);
userDic.RemoveWord(listBox1.Text)

The following screenshot shows the interface of the sample application:

Image