Back to Devexpress

How To: Customize the Spelling Dialog

windowsforms-116931-controls-and-libraries-spell-checker-examples-how-to-customize-the-spelling-dialog.md

latest4.9 KB
Original Source

How To: Customize the Spelling Dialog

  • May 23, 2019
  • 3 minutes to read

Customize the Dialog

This example demonstrates how to customize the spell checker’s Spelling Dialog and the messages that occur when the spelling check is complete.

You can modify layouts of both Outlook-inspired and Word-inspired Spelling Dialogs by doing the following.

  1. Handle the SpellChecker.SpellingFormShowing event. It is raised when the form is about to be shown.
  2. Retrieve the Spelling Dialog’s form from the SpellChecker.FormsManager collection.
  3. Modify the form’s Controls collection to hide default buttons and/or to add custom control.
csharp
private void spellChecker1_SpellingFormShowing(object sender, DevExpress.XtraSpellChecker.SpellingFormShowingEventArgs e)
{
    var spellDialogForm = spellChecker1.FormsManager.SpellCheckForm;

    spellDialogForm.Controls["btnIgnore"].Enabled = false;
    spellDialogForm.Controls["btnIgnoreAll"].Visible = false;
    spellDialogForm.Controls["btnChangeAll"].Visible = false;
    spellDialogForm.Controls.Add(new SimpleButton() { Text = "Custom Button", Size = new Size(100, 25), Location = new Point(10, 150) });
}
vb
Private Sub spellChecker1_SpellingFormShowing(ByVal sender As Object, ByVal e As DevExpress.XtraSpellChecker.SpellingFormShowingEventArgs) Handles spellChecker1.SpellingFormShowing
    Dim spellDialogForm = spellChecker1.FormsManager.SpellCheckForm

    spellDialogForm.Controls("btnIgnore").Enabled = False
    spellDialogForm.Controls("btnIgnoreAll").Visible = False
    spellDialogForm.Controls("btnChangeAll").Visible = False
    spellDialogForm.Controls.Add(New SimpleButton() With {.Text = "Custom Button", .Size = New Size(100, 25), .Location = New Point(10, 150)})
End Sub

The following image illustrates a customized Spelling Dialog.

Table of Controls

The code sample above utilizes default control names to access them. The following table gives names for all of these default controls, owned by a spelling dialog.

Element CaptionControlElement Name
Add to Dictionary (Add) buttonSimpleButtonbtnAdd
Cancel buttonSimpleButtonbtnCancel
Change buttonSimpleButtonbtnChange
Change All buttonSimpleButtonbtnChangeAll
Close buttonSimpleButtonbtnClose
Ignore Once (Ignore) buttonSimpleButtonbtnIgnore
Ignore All buttonSimpleButtonbtnIgnoreAll
Undo Last buttonSimpleButtonbtnUndoLast
Not In Dictionary labelLabelEditlblNotInDictionary
Suggestions labelLabelEditlblSuggestions
Repeated Word labelLabelEditlblRepeatedWord
Delete buttonSimpleButtonbtnDelete
Not in Dictionary memo edit (Word-type form)CustomSpellCheckMemoEditmmNotInDictionary
Suggestions list boxListBoxControllbcSuggestions
Options buttonSimpleButtonbtnOptions
Not in Dictionary text edit (Outlook-type form)TextEdittxtNotInDictionary
Change to: text edit (Outlook-type form)TextEdittxtChangeTo

Disable Messages

If the end user checks spelling of a selection in a text editor (MemoEdit or RichTextBox), the following message appears after the check is complete:

Handle the SpellCheckerBase.FinishCheckingMainPart event to specify whether to check the remaining text and hide the message. Specify the FinishCheckingMainPartEventArgs.NeedCheckRemainingPart property as shown below:

csharp
private void SpellChecker1_FinishCheckingMainPart(object sender, FinishCheckingMainPartEventArgs e)
{
    e.NeedCheckRemainingPart = false;
}
vb
Private Sub SpellChecker1_FinishCheckingMainPart(ByVal sender As Object, ByVal e As FinishCheckingMainPartEventArgs)
    e.NeedCheckRemainingPart = False
End Sub

The SpellChecker.CheckCompleteFormShowing event allows you to hide the Spelling Check Is Complete message.

Set the Handled parameter to true in the event handler to disable this message.