New to Telerik UI for WinForms? Download free 30-day trial

Replace Default Dialogs

This article will demonstrate how you can replace the default FindAndRepacle dialog with a custom one. It will show which dialogs can be replaced as well.

Create Custom Dialog

1. Let's start by adding a simple RadForm to our project (the main form of the project should contain at least one RadRichTextEditor). Make the form to look like in the following picture (you can leave the default control names).

WinForms RadRichTextEditor Custom Dialog

2. Open the code behind and add event handler for the button. You can add a method that will perform the search as well:

private void radButton1_Click(object sender, EventArgs e)
    string textToFind = radTextBox1.Text;
    var color = radColorBox1.Value;

private void SelectAllMatches(string toSearch)
    DocumentTextSearch search = new DocumentTextSearch(this.richTextBox.Document);
    foreach (var textRange in search.FindAll(toSearch))

Private Sub radButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim textToFind As String = radTextBox1.Text
    Dim color = radColorBox1.Value
End Sub
Private Sub SelectAllMatches(ByVal toSearch As String)
    Dim search As New DocumentTextSearch(Me.richTextBox.Document)
    For Each textRange In search.FindAll(toSearch)
    Next textRange
End Sub

3. The new dialog need to implement the IFindReplaceDialog otherwise you cannot replace the default one. So go ahead and add the interface to the form's class declaration:

public partial class FindAllDialog : RadForm, IFindReplaceDialog

Partial Public Class FindAllDialog
    Inherits RadForm
    Implements IFindReplaceDialog

Now, you are ready to add the required fields, property and methods:

RadRichTextBox richTextBox;
bool isOpen;

public bool IsOpen
        return this.isOpen;

public void Show(RadRichTextBox richTextBox, Func<string, bool> replaceCallback, string textToFind)
    this.Owner = richTextBox.ElementTree.Control.FindForm();
    this.richTextBox = richTextBox;

protected override void OnShown(EventArgs e)
    this.isOpen = true;

protected override void OnActivated(EventArgs e)
    this.isOpen = false;

Private richTextBox As RadRichTextBox
Private _isOpen As Boolean
Public ReadOnly Property IsOpen() As Boolean Implements IFindReplaceDialog.IsOpen
        Return Me._isOpen
    End Get
End Property
Public Sub Show(ByVal richTextBox As RadRichTextBox, ByVal replaceCallback As Func(Of String, Boolean), ByVal textToFind As String) Implements IFindReplaceDialog.Show
    Me.Owner = richTextBox.ElementTree.Control.FindForm()
    Me.richTextBox = richTextBox
End Sub
Public Sub Close() Implements IFindReplaceDialog.Close
End Sub
Protected Overrides Sub OnShown(ByVal e As EventArgs)
    Me._isOpen = True
End Sub
Protected Overrides Sub OnActivated(ByVal e As EventArgs)
    Me._isOpen = False
End Sub

4. The final step is to assign a new instance of the dialog to the corresponding property:

radRichTextEditor1.RichTextBoxElement.FindReplaceDialog = new FindAllDialog();

radRichTextEditor1.RichTextBoxElement.FindReplaceDialog = New FindAllDialog()

Dialogs that can be replaced

The following list shows which dialogs can be replaced in RadRichTextEditor:

  • AddNewBibliographicSourceDialog

  • ChangeEditingPermissionsDialog

  • CodeFormattingDialog

  • EditCustomDictionaryDialog

  • FindReplaceDialog

  • FloatingBlockPropertiesDialog

  • FontPropertiesDialog

  • InsertCaptionDialog

  • InsertCrossReferenceWindow

  • InsertDateTimeDialog

  • InsertHyperlinkDialog

  • InsertSymbolDialog

  • InsertTableDialog

  • InsertTableOfContentsDialog

  • ManageBibliographicSourcesDialog

  • ManageBookmarksDialog

  • ManageStylesDialog

  • NewCaptionLabelDialog

  • NotesDialog

  • ParagraphPropertiesDialog

  • ProtectDocumentDialog

  • SetNumberingValueDialog

  • SpellCheckingDialog

  • StyleFormattingPropertiesDialog

  • TablePropertiesDialog

  • TabStopsPropertiesDialog

  • UnprotectDocumentDialog

  • WatermarkSettingsDialog

In this article