# Customizing the Spell Check Dialog

> Rename, remove and add buttons of the Windows Forms spell check dialog with DialogButtonCollection, handle DialogButtonClicked, and change font and preview.

- **Product:** TX Spell .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for Windows Forms > User Interface > Customizing the Spell Check Dialog
- **4014 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/customizing-dialog/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/customizing-dialog/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/customizing-dialog/llms-full.txt

---

Your application may need a spelling dialog that differs from the default one: without **Add To Dictionary** because users must not change the dictionaries, with a button that ends the check, in the font of the application, or with an options dialog of your own. The spell check dialog of TX Spell .NET can be changed in all these ways, in code, before it opens. What follows shows each change, and a form that combines them.

### How the Dialog Is Built

You don't create the dialog. The [SpellCheckDialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/spellcheckdialog-property/llms-full.txt) property of the `TXSpellChecker` returns it, a [SpellCheckDialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/llms-full.txt) object that keeps its settings for every time the dialog is shown. Its buttons are in three collections, one for each group of the dialog:

| Collection | Place in the dialog | Default buttons |
|---|---|---|
| [IgnoreButtons](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/ignorebuttons-property/llms-full.txt) | Right of the sentence | **Ignore Once**, **Ignore All**, **Add To Dictionary** |
| [ChangeButtons](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/changebuttons-property/llms-full.txt) | Right of the suggestions | **Change**, **Change All** |
| [OptionButtons](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/optionbuttons-property/llms-full.txt) | Below the suggestions dictionary | **Options...** |

Each collection is a [DialogButtonCollection](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbuttoncollection/llms-full.txt) of [DialogButton](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbutton/llms-full.txt) objects. A button has a [Text](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbutton/text-property/llms-full.txt), an [Enabled](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbutton/enabled-property/llms-full.txt) state, a [Font](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbutton/font-property/llms-full.txt) and a [Type](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbutton/type-property/llms-full.txt), a value of [TXSpell.ButtonType](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspell-buttontype/enumeration/llms-full.txt) that decides what a click does. [Spell Check Dialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/spell-check-dialog/llms-full.txt) lists the types of the default buttons.

Change the collections while the dialog is closed. [Add](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbuttoncollection/add-method/llms-full.txt), [AddRange](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbuttoncollection/addrange-method/llms-full.txt) and [Remove](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbuttoncollection/remove-method/llms-full.txt) throw an exception when they are called while it is open. The form's constructor is a good place.

### The Modify SpellCheckDialog Sample

The setup installs a sample that changes the dialog, in the *Modify SpellCheckDialog* folder of the Windows Forms samples. Its window has check boxes for the changes; the user sets them and opens the dialog to see the result:

![The window of the Modify SpellCheckDialog sample with a text to check and the check boxes With Own Options Dialog and Show Add To Dictionary, next to the Spelling dialog it opens.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/modify-dialog-sample.0ce8ca19.webp)

To see a change, close the dialog, change the settings and open it again. [Spell Checking Examples](https://docs.textcontrol.com/tx-spell-dotnet-winforms/examples/spell-checking/llms-full.txt) lists this sample with the other samples of the setup.

### Rename a Button

Set the `Text` of a button. The sample renames the options button when its check box is checked:

```csharp
txSpellChecker1.SpellCheckDialog.OptionButtons[0].Text = checkBox1.Checked ? "My Options..." : "Options...";
```

The indexer of a collection counts from 0, in the order of the table above. The new text is used the next time the dialog opens.

### Remove or Disable a Button

To take **Add To Dictionary** away from the user, find it by its type and remove it from its collection:

```csharp
SpellCheckDialog dialog = txSpellChecker1.SpellCheckDialog;

foreach (DialogButton button in dialog.IgnoreButtons)
{
    if (button.Type == TXSpell.ButtonType.AddToDictionary)
    {
        dialog.IgnoreButtons.Remove(button);
        break;
    }
}
```

To keep the button visible but grayed out, set its `Enabled` property to `false` instead. Removing the **Options...** button from `OptionButtons` the same way leaves the user no way to open the options dialog from the spell check dialog.

### Add a Button of Your Own

A button of the type `User` has no built-in behavior. You create it, add it to a collection and handle its click in the [DialogButtonClicked](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/dialogbuttonclicked-event/llms-full.txt) event of the `TXSpellChecker`. This **Stop** button, added to the group of **Change** and **Change All**, ends the check:

```csharp
private DialogButton stopButton;

private void AddStopButton()
{
    stopButton = new DialogButton(TXSpell.ButtonType.User);
    stopButton.Text = "Stop";
    txSpellChecker1.SpellCheckDialog.ChangeButtons.Add(stopButton);

    txSpellChecker1.DialogButtonClicked += txSpellChecker1_DialogButtonClicked;
}

private void txSpellChecker1_DialogButtonClicked(object sender, DialogButtonEventArgs e)
{
    if (e.DialogButton == stopButton)
    {
        // Close the dialog before all words are checked
        e.StateManager.Close();
    }
}
```

The code works as follows:

- The [DialogButton](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbutton/llms-full.txt) constructor takes the type of the button. `ChangeButtons.Add` places it in the group of **Change** and **Change All**.
- [DialogButtonEventArgs](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbuttoneventargs/llms-full.txt) tells which button was clicked, in [DialogButton](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbuttoneventargs/dialogbutton-property/llms-full.txt). The event fires for every button of the dialog, so compare the button before you act.
- [StateManager](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dialogbuttoneventargs/statemanager-property/llms-full.txt) is a [SpellCheckDialogStateManager](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialogstatemanager/llms-full.txt). Its [Close](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialogstatemanager/close-method/llms-full.txt) method closes the dialog; its [SetNext](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialogstatemanager/setnext-method/llms-full.txt) method moves the dialog to another word, text or control.

### Change the Font and the Preview

The [Font](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/font-property/llms-full.txt) of the `SpellCheckDialog` is used by its labels, the preview, the two lists and the **Cancel** button. The other buttons have a font of their own. The [Preview](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/preview-property/llms-full.txt) property describes the sentence at the top of the dialog:

| Property | Default | Effect |
|---|---|---|
| `SpellCheckDialog.Font` | `Control.DefaultFont` | The font of the labels, the preview, the lists and **Cancel** |
| [Preview.IncorrectWordColor](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/preview/incorrectwordcolor-property/llms-full.txt) | `Color.Red` | The color of the misspelled word in the sentence |
| [Preview.Editable](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/preview/editable-property/llms-full.txt) | `true` | Whether the user can edit the sentence |

One more property concerns the editor behind the dialog. [HideSelection](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/hideselection-property/llms-full.txt) decides whether the text selected in the `TextControl` stays highlighted while the dialog is open. Its default is `false`, and it has an effect only when the dialog checks a `TextControl`.

The two lists of the dialog, the suggestions and the suggestions dictionary, are described in [Suggestion Controls](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/suggestions/llms-full.txt).

### Use Your Own Options Dialog

The **Options...** button raises the [OptionsDialogOpening](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/optionsdialogopening-event/llms-full.txt) event before the options dialog of TX Spell .NET opens. Set `Cancel` of its arguments to `true` and show your own form instead; the sample's **With Own Options Dialog** check box does this. [Options Dialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/options-dialog/#replace-the-dialog-with-your-own) shows the code.

### Put It Together

This form connects a spell checker to a `TextControl` and changes the dialog in its constructor: **Add To Dictionary** is removed, a **Stop** button is added, **Change** answers the Enter key, and the font, the color and the number of suggestions are changed. 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:

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

public class SpellingForm : Form
{
    private readonly TXTextControl.TextControl textControl1 = new TXTextControl.TextControl();
    private readonly TXSpellChecker txSpellChecker1 = new TXSpellChecker();
    private readonly System.Windows.Forms.Button buttonSpelling = new System.Windows.Forms.Button();
    private DialogButton stopButton;

    public SpellingForm()
    {
        textControl1.Dock = DockStyle.Fill;
        textControl1.SpellChecker = txSpellChecker1;
        textControl1.IsSpellCheckingEnabled = true;

        buttonSpelling.Text = "Spelling...";
        buttonSpelling.Dock = DockStyle.Bottom;
        buttonSpelling.Click += (sender, e) => txSpellChecker1.SpellCheckDialog.Show(textControl1);

        Controls.Add(textControl1);
        Controls.Add(buttonSpelling);

        SpellCheckDialog dialog = txSpellChecker1.SpellCheckDialog;

        // Users may not change the dictionaries
        foreach (DialogButton button in dialog.IgnoreButtons)
        {
            if (button.Type == TXSpell.ButtonType.AddToDictionary)
            {
                dialog.IgnoreButtons.Remove(button);
                break;
            }
        }

        // A button that ends the check
        stopButton = new DialogButton(TXSpell.ButtonType.User);
        stopButton.Text = "Stop";
        dialog.ChangeButtons.Add(stopButton);
        txSpellChecker1.DialogButtonClicked += txSpellChecker1_DialogButtonClicked;

        // Enter clicks Change instead of Ignore Once
        dialog.AcceptButton = dialog.ChangeButtons[0];

        dialog.Font = new Font("Segoe UI", 10);
        dialog.Preview.IncorrectWordColor = Color.Blue;
        dialog.SuggestionList.MaxSuggestions = 5;
    }

    private void txSpellChecker1_DialogButtonClicked(object sender, DialogButtonEventArgs e)
    {
        if (e.DialogButton == stopButton)
        {
            e.StateManager.Close();
        }
    }

    [STAThread]
    private static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new SpellingForm());
    }
}
```

Run the application, type a few misspelled words and click **Spelling...**. The dialog opens without **Add To Dictionary**, with a **Stop** button in the group of **Change** and **Change All**, and the misspelled word appears in blue.

The code works as follows:

- `System.Windows.Forms.Button` is written in full because the `TXTextControl` namespace has a `Button` class, too.
- [AcceptButton](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spellcheckdialog/acceptbutton-property/llms-full.txt) is the button that Enter clicks. It is **Ignore Once** by default; `ChangeButtons[0]` is **Change**.
- [MaxSuggestions](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestionlist/maxsuggestions-property/llms-full.txt) limits the suggestion list to five words instead of ten.

### Next Steps

- [Spell Check Dialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/spell-check-dialog/llms-full.txt): the parts of the dialog and what each button does.
- [Options Dialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/options-dialog/llms-full.txt): the dialog behind **Options...**, and how to replace it.
- [Suggestion Controls](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/suggestions/llms-full.txt): the suggestion list and the dictionary list of the dialog.
- [Localization and Resource Kit](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/localization/llms-full.txt): the texts of the dialog in other languages.
- [Spelling Correction Modes and UI Provider](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/correction-modes/llms-full.txt): a spelling dialog built entirely from your own controls.

---

## Nearby

- **Previous:** [Spell Check Dialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/spell-check-dialog/llms-full.txt)
- **Next:** [Options Dialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/options-dialog/llms-full.txt)
