# Customizing the Spell Check Dialog

> Change the WPF spell check dialog in code: DialogButton collections, a User button with DialogButtonClicked, FontFamily, preview color and AcceptButton.

- **Product:** TX Spell .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for WPF > User Interface > Customizing the Spell Check Dialog
- **4185 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/customizing-dialog/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/customizing-dialog/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/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 window that combines them.

### How the Dialog Is Built

You don't create the dialog. The [SpellCheckDialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/spellcheckdialog-property/llms-full.txt) property of the `TXSpellChecker` returns it, a [SpellCheckDialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/llms-full.txt) object that keeps its settings for every time the dialog is shown. By default, it looks like this:

![The Spelling dialog over a TextControl, with the sentence and the misspelled word "sampke" in red, the buttons Ignore Once, Ignore All and Add To Dictionary, the suggestions with the buttons Change and Change All, the Suggestions Dictionary en_US.dic, Options and Cancel.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-wpf/textcontrol-spelling-dialog.0a7b34fc.webp)

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-wpf/reference/txtextcontrol-wpf-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-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/changebuttons-property/llms-full.txt) | Right of the suggestions | **Change**, **Change All** |
| [OptionButtons](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/optionbuttons-property/llms-full.txt) | Below the suggestions dictionary | **Options...** |

Each collection is a [DialogButtonCollection](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/dialogbuttoncollection/llms-full.txt) of [DialogButton](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/dialogbutton/llms-full.txt) objects. A button has a [Text](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/dialogbutton/text-property/llms-full.txt), an [Enabled](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/dialogbutton/enabled-property/llms-full.txt) state, font properties and a [Type](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/dialogbutton/type-property/llms-full.txt), a value of [TXSpell.ButtonType](https://docs.textcontrol.com/tx-spell-dotnet-wpf/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-wpf/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-wpf/reference/txtextcontrol-wpf-proofing/dialogbuttoncollection/add-method/llms-full.txt), [AddRange](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/dialogbuttoncollection/addrange-method/llms-full.txt) and [Remove](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/dialogbuttoncollection/remove-method/llms-full.txt) throw an exception when they are called while it is open. The constructor of the window is a good place.

The dialog classes are in the `TXTextControl.WPF.Proofing` namespace, and `TXSpell.ButtonType` is in `TXTextControl.Proofing`. The code on this page uses both namespaces.

### Rename a Button

Set the `Text` of a button:

```csharp
txSpellChecker1.SpellCheckDialog.OptionButtons[0].Text = "My 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-wpf/reference/txtextcontrol-wpf-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-wpf/reference/txtextcontrol-wpf-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-wpf/reference/txtextcontrol-wpf-proofing/dialogbuttoneventargs/llms-full.txt) tells which button was clicked, in [DialogButton](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-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-wpf/reference/txtextcontrol-wpf-proofing/dialogbuttoneventargs/statemanager-property/llms-full.txt) is a [SpellCheckDialogStateManager](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialogstatemanager/llms-full.txt). Its [Close](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialogstatemanager/close-method/llms-full.txt) method closes the dialog; its [SetNext](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialogstatemanager/setnext-method/llms-full.txt) method moves the dialog to another word, text or control.

### Change the Font and the Preview

Four properties of the `SpellCheckDialog` set the font of its labels, the preview, the two lists and the **Cancel** button: [FontFamily](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/fontfamily-property/llms-full.txt), [FontSize](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/fontsize-property/llms-full.txt), [FontStyle](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/fontstyle-property/llms-full.txt) and [FontWeight](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/fontweight-property/llms-full.txt). The other buttons have font properties of their own with the same names. The [Preview](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/preview-property/llms-full.txt) property describes the sentence at the top of the dialog:

| Property | Default | Effect |
|---|---|---|
| [Preview.IncorrectWordColor](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/preview/incorrectwordcolor-property/llms-full.txt) | `Colors.Red` | The color of the misspelled word in the sentence |
| [Preview.Editable](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-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-wpf/reference/txtextcontrol-wpf-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-wpf/user-interface/suggestions/llms-full.txt).

### Use Your Own Options Dialog

The **Options...** button raises the [OptionsDialogOpening](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-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 window instead. [Options Dialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/options-dialog/#replace-the-dialog-with-your-own) shows the code.

### Put It Together

This window 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. In a new WPF project with the TX Text Control and TX Spell .NET packages, replace the contents of *MainWindow.xaml*, and change `SpellingApp` to the namespace of your project:

```xml
<Window x:Class="SpellingApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:tx="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF"
        xmlns:spell="clr-namespace:TXTextControl.WPF.Proofing;assembly=TXSpell.WPF"
        Title="Spelling" Height="450" Width="800">
    <Window.Resources>
        <spell:TXSpellChecker x:Key="txSpellChecker1" />
    </Window.Resources>
    <DockPanel>
        <Button DockPanel.Dock="Bottom" Content="Spelling..." Click="ButtonSpelling_Click" />
        <tx:TextControl Name="textControl1"
                        IsSpellCheckingEnabled="True"
                        SpellChecker="txSpellChecker1" />
    </DockPanel>
</Window>
```

Then replace the contents of *MainWindow.xaml.cs*:

```csharp
using System.Windows;
using System.Windows.Media;
using TXTextControl.Proofing;
using TXTextControl.WPF.Proofing;

namespace SpellingApp
{
    public partial class MainWindow : Window
    {
        private readonly TXSpellChecker txSpellChecker1;
        private readonly DialogButton stopButton;

        public MainWindow()
        {
            InitializeComponent();
            txSpellChecker1 = (TXSpellChecker)FindResource("txSpellChecker1");

            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.FontFamily = new FontFamily("Segoe UI");
            dialog.FontSize = 13;
            dialog.Preview.IncorrectWordColor = Colors.Blue;
            dialog.SuggestionList.MaxSuggestions = 5;
        }

        private void ButtonSpelling_Click(object sender, RoutedEventArgs e)
        {
            txSpellChecker1.SpellCheckDialog.Show(textControl1);
        }

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

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:

- The window needs two namespaces: `TXTextControl.WPF.Proofing` for the spell checker and its dialog, and `TXTextControl.Proofing` for `TXSpell.ButtonType`.
- [AcceptButton](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-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-wpf/reference/txtextcontrol-wpf-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-wpf/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-wpf/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-wpf/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-wpf/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-wpf/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-wpf/user-interface/spell-check-dialog/llms-full.txt)
- **Next:** [Options Dialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/options-dialog/llms-full.txt)
