# Suggestion Controls

> Set the suggestion list and dictionary list of the Windows Forms spell check dialog, and show CreateSuggestions results in a ListBox below the misspelled word.

- **Product:** TX Spell .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for Windows Forms > User Interface > Suggestion Controls
- **4040 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/suggestions/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/suggestions/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/suggestions/llms-full.txt

---

Suggestions are the words TX Spell .NET offers in place of a misspelled one. The user sees them in the list of the spell check dialog, at the top of the context menu, or in a control of your own that you fill. TX Spell .NET has no separate suggestion control to drop on a form: you set up the lists of its dialog and menu, or you show suggestions in a standard `ListBox`. Each of these places is covered below, with what it shows and the properties that change it.

### Where Suggestions Appear

| Place | What you set | Covered in |
|---|---|---|
| **Suggestions** list of the spell check dialog | [SuggestionList](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestionlist/llms-full.txt) | [The Suggestion List of the Dialog](#the-suggestion-list-of-the-dialog) |
| **Suggestions Dictionary** list of the dialog | [SuggestionDictionaryComboBox](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestiondictionarycombobox/llms-full.txt) | [The Suggestions Dictionary List](#the-suggestions-dictionary-list) |
| Top of the context menu | The `maxSuggestions` parameter of `GetMenuItems` | [Suggestions in the Context Menu](#suggestions-in-the-context-menu) |
| A control of your own | `CreateSuggestions` or the `SpellingCorrectionUIProvider` | [Show Suggestions Next to the Word](#show-suggestions-next-to-the-word) |

Which suggestions are found at all depends on the dictionaries: only a dictionary whose [IsGetSuggestionsEnabled](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dictionary/isgetsuggestionsenabled-property/llms-full.txt) property is `true` provides suggestions. It is `true` by default, and the user changes it in the **Suggestions** column of the [Options Dialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/options-dialog/#the-spell-checking-dictionaries-tab).

### The Suggestion List of the Dialog

The spell check dialog lists the suggestions for the current word below the sentence. The [SuggestionList](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/suggestionlist-property/llms-full.txt) property of the `SpellCheckDialog` describes this list:

![The Spelling dialog over a RichTextBox with the misspelled word "sampke" and the suggestions sample, spake, smoke, samples, sampler and sampled in the Suggestions list.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/richtextbox-spelling-dialog.b515f6c9.webp)

| Property | Default | Effect |
|---|---|---|
| [MaxSuggestions](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestionlist/maxsuggestions-property/llms-full.txt) | 10 | The largest number of suggestions in the list |
| [IsNoSuggestionsItemEnabled](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestionlist/isnosuggestionsitemenabled-property/llms-full.txt) | `true` | When no suggestion is found, the list shows an item that says so |

Set them before the dialog opens, for example in the constructor of the form:

```csharp
using TXTextControl.Proofing;

SpellCheckDialog dialog = txSpellChecker1.SpellCheckDialog;

// Show the five best suggestions only
dialog.SuggestionList.MaxSuggestions = 5;

// Offer "All" in the Suggestions Dictionary list
dialog.SuggestionDictionaryComboBox.IsAllItemEnabled = true;
```

The second setting belongs to the list below the suggestions, described next.

### The Suggestions Dictionary List

**Suggestions Dictionary** chooses the dictionary the suggestions come from. With one dictionary, it shows that dictionary. With several, for example English and a dictionary of medical terms, the user switches between them, and the list of suggestions changes with the choice:

![The Spelling dialog over TX Text Control Words with the Suggestions Dictionary list open, offering en_US.dic and Shared Medical Dictionary.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/spelling-dialog-dict-list.87947a59.webp)

The [SuggestionDictionaryComboBox](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/suggestiondictionarycombobox-property/llms-full.txt) property of the `SpellCheckDialog` describes this list:

| Property | Default | Effect |
|---|---|---|
| [IsAllItemEnabled](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestiondictionarycombobox/isallitemenabled-property/llms-full.txt) | `false` | Adds an **All** item that takes suggestions from all dictionaries at once. It appears only when more than one dictionary provides suggestions |
| [IsAllItemSelected](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestiondictionarycombobox/isallitemselected-property/llms-full.txt) | `false` | Whether **All** is selected |
| [SuggestionDictionary](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestiondictionarycombobox/suggestiondictionary-property/llms-full.txt) |  | The selected [Dictionary](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dictionary/llms-full.txt), or `null` when **All** is selected |

The list shows a dictionary by its file name, such as *en\_US.dic*, unless you give it a [DisplayName](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dictionary/displayname-property/llms-full.txt). The picture shows "Shared Medical Dictionary" as the display name of a second dictionary. [Options Dialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/options-dialog/#hide-or-rename-a-dictionary) sets one in code.

To open the dialog with suggestions from one dictionary, pass it to [Show](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/show-method/llms-full.txt), as in `Show(textControl1, dictionary)`.

### Suggestions in the Context Menu

The context menu of a misspelled word starts with its suggestions. When you build the menu yourself with [GetMenuItems](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/getmenuitems-method/llms-full.txt), its last parameter is the largest number of suggestions:

![Four TextControls with red underlines, and the context menu of a misspelled word with its suggestions at the top.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/four-textcontrols-context.0b87ecfe.webp)

The *Context menu strip* samples of the setup pass 5. When no suggestion is found, the menu shows an item of the type `NoSuggestions` in their place. [Context Menus](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/context-menus/llms-full.txt) builds the whole menu.

### Show Suggestions Next to the Word

Suggestions can also appear while the user types, right below the misspelled word, without a right-click. The blog article [Interactive Spelling Suggestions Using TX Spell .NET](https://www.textcontrol.com/blog/2014/07/30/interactive-spelling-suggestions-using-tx-spell-net/) shows a sample that does this with a panel of tiles:

![A TextControl in the AutoText sample: while the word "Suggestion" is typed, a panel of tiles below it offers suggestions such as Suggest and Surges, and a click replaces the word.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/suggestion-panel-autotext.18cd7be8.webp)

This form does the same with a `ListBox`. 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; add a `Main` method or create the form from *Program.cs*:

```csharp
using System.Drawing;
using System.Windows.Forms;
using TXTextControl;
using TXTextControl.Proofing;

public class SuggestForm : Form
{
    private readonly TextControl textControl1 = new TextControl();
    private readonly TXSpellChecker txSpellChecker1 = new TXSpellChecker();
    private readonly ListBox suggestionList = new ListBox();

    public SuggestForm()
    {
        textControl1.Dock = DockStyle.Fill;
        textControl1.SpellChecker = txSpellChecker1;
        textControl1.IsSpellCheckingEnabled = true;
        Controls.Add(textControl1);

        // The list floats over the text, hidden until there are suggestions
        suggestionList.Visible = false;
        suggestionList.Width = 150;
        suggestionList.Height = 100;
        textControl1.Controls.Add(suggestionList);
        suggestionList.MouseClick += suggestionList_MouseClick;

        textControl1.Changed += (sender, e) => ShowSuggestions();
        textControl1.InputPositionChanged += (sender, e) => ShowSuggestions();
        textControl1.Zoomed += (sender, e) => ShowSuggestions();
    }

    private void ShowSuggestions()
    {
        // The misspelled word at the input position
        MisspelledWord word = textControl1.MisspelledWords.GetItem();
        if (word == null || textControl1.Selection.Start < word.Start - 1
            || textControl1.Selection.Start > word.Start + word.Length - 1)
        {
            suggestionList.Visible = false;
            return;
        }

        txSpellChecker1.CreateSuggestions(word.Text, 6);
        if (txSpellChecker1.Suggestions.Count == 0)
        {
            suggestionList.Visible = false;
            return;
        }

        suggestionList.Items.Clear();
        foreach (Suggestion suggestion in txSpellChecker1.Suggestions)
        {
            suggestionList.Items.Add(suggestion.Text);
        }

        // Place the list below the word; the text positions are in twips
        int twipsPerPixel = (int)(1440 / textControl1.CreateGraphics().DpiX);
        Rectangle bounds = textControl1.TextChars[word.Start].Bounds;
        suggestionList.Location = new Point(
            (bounds.Left - textControl1.ScrollLocation.X) / twipsPerPixel * textControl1.ZoomFactor / 100,
            (bounds.Bottom - textControl1.ScrollLocation.Y) / twipsPerPixel * textControl1.ZoomFactor / 100);
        suggestionList.Visible = true;
    }

    private void suggestionList_MouseClick(object sender, MouseEventArgs e)
    {
        if (suggestionList.SelectedItem == null) return;

        // Replace the misspelled word with the clicked suggestion
        textControl1.MisspelledWords.Remove(textControl1.MisspelledWords.GetItem(), suggestionList.SelectedItem.ToString());
        suggestionList.Visible = false;
        textControl1.Focus();
    }
}
```

The code works as follows:

- The `Changed`, `InputPositionChanged` and `Zoomed` events of the `TextControl` update the list whenever the text, the input position or the zoom changes.
- [GetItem](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledwordcollection/getitem-method/llms-full.txt) without a parameter returns the misspelled word at the input position, or the next one when there is none. The comparison with [Selection.Start](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/selection/start-property/llms-full.txt) hides the list when the input position is not in the word or directly in front of or behind it. `Selection.Start` counts from 0 and `Start` of the word from 1.
- [CreateSuggestions](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/createsuggestions-method/llms-full.txt) creates at most six suggestions for the word and stores them in [Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/suggestions-property/llms-full.txt), a collection of [Suggestion](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestion/llms-full.txt) objects with a [Text](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestion/text-property/llms-full.txt).
- [Bounds](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textchar/bounds-property/llms-full.txt) of the first character of the word, in twips, gives the position below the word. [ScrollLocation](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/scrolllocation-property/llms-full.txt) and [ZoomFactor](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/zoomfactor-property/llms-full.txt) turn it into a position on the screen.
- [Remove](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledwordcollection/remove-method/llms-full.txt) of the `MisspelledWords` collection replaces the word with the clicked suggestion.

[Incorrect Words and Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/suggestions/llms-full.txt) explains `CreateSuggestions` and its overloads in detail.

### Bind a List to the Correction Provider

For a correction panel that works through the misspelled words one by one, like the dialog, bind a `ListBox` to the [SpellingCorrectionUIProvider](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellingcorrectionuiprovider/llms-full.txt). Its [Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellingcorrectionuiprovider-suggestionshandler/suggestions-property/llms-full.txt) always hold the suggestions for the current word, and its [SuggestionDictionaries](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellingcorrectionuiprovider-suggestiondictionarieshandler/suggestiondictionaries-property/llms-full.txt) fill a list of dictionaries like the one of the dialog. The list updates through data binding, without event handlers of yours. [Spelling Correction Modes and UI Provider](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/correction-modes/llms-full.txt) builds such a panel.

### Next Steps

- [Incorrect Words and Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/suggestions/llms-full.txt): create suggestions in code.
- [Context Menus](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/context-menus/llms-full.txt): the menu with the suggestions at the top.
- [Customizing the Spell Check Dialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/customizing-dialog/llms-full.txt): change the buttons, the font and the preview of the dialog.
- [Loading and Managing Dictionaries](https://docs.textcontrol.com/tx-spell-dotnet-winforms/dictionaries/managing/llms-full.txt): add the dictionaries that suggestions come from.

---

## Nearby

- **Previous:** [Context Menus](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/context-menus/llms-full.txt)
- **Next:** [Localization and Resource Kit](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/localization/llms-full.txt)
