Back to Devexpress

RichEditControl.ShowSearchForm() Method

windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-34956722.md

latest5.3 KB
Original Source

RichEditControl.ShowSearchForm() Method

Invokes the “Find and Replace” dialog.

Namespace : DevExpress.XtraRichEdit

Assembly : DevExpress.XtraRichEdit.v25.2.dll

NuGet Package : DevExpress.Win.RichEdit

Declaration

csharp
public virtual void ShowSearchForm()
vb
Public Overridable Sub ShowSearchForm

Remarks

Use the FindCommand or ReplaceCommand commands to show the Find and Replace dialog.

To customize the search form, make a descendant and override the required methods, as shown in the How to: Customize the Search Form document.

To create your own form, use the XtraRichEdit API. It provides the ISearchResult interface which defines methods required to perform a text search in the document.

Example

The following code invokes the Find and Replace dialog switched to the ‘Find’ tab with the word ‘test’ used for search. The current RichEditControl instance is passed to the BarItem.ItemClick event handler using the BarItem.Tag property.

View Example

csharp
static void buttonCustomAction_ItemClick_ShowSearchFormMethod(object sender, ItemClickEventArgs e) {
    RichEditControl richEdit = e.Item.Tag as RichEditControl;
    richEdit.ShowSearchForm();
    var searchForm = Application.OpenForms.Cast<Form>().Last() as DevExpress.XtraRichEdit.Forms.SearchTextForm;
    if(searchForm != null) {
        System.Windows.Forms.Control[] searchBoxes = searchForm.Controls.Find("cbFndSearchString", true);
        if(searchBoxes.Length > 0) searchBoxes[0].Text = "test";
    }
}
vb
Private Shared Sub buttonCustomAction_ItemClick_ShowSearchFormMethod(ByVal sender As Object, ByVal e As ItemClickEventArgs)
    Dim richEdit As RichEditControl = TryCast(e.Item.Tag, RichEditControl)
    richEdit.ShowSearchForm()
    Dim searchForm As DevExpress.XtraRichEdit.Forms.SearchTextForm =
        TryCast(Application.OpenForms.Cast(Of Form)().Last(), DevExpress.XtraRichEdit.Forms.SearchTextForm)
    If searchForm IsNot Nothing Then
        Dim searchBoxes() As System.Windows.Forms.Control = searchForm.Controls.Find("cbFndSearchString", True)
        If searchBoxes.Length > 0 Then
            searchBoxes(0).Text = "test"
        End If
    End If
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ShowSearchForm() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-richeditcontrol-common-api/CS/RichEditAPISample/CodeExamples/RichEditControlActions.cs#L27

csharp
RichEditControl richEdit = e.Item.Tag as RichEditControl;
richEdit.ShowSearchForm();
var searchForm = Application.OpenForms.Cast<Form>().Last() as DevExpress.XtraRichEdit.Forms.SearchTextForm;

winforms-richeditcontrol-common-api/VB/RichEditAPISample/CodeExamples/RichEditControlActions.vb#L29

vb
Dim richEdit As RichEditControl = TryCast(e.Item.Tag, RichEditControl)
richEdit.ShowSearchForm()
Dim searchForm As DevExpress.XtraRichEdit.Forms.SearchTextForm =

See Also

FindCommand

ReplaceCommand

ISearchResult

RichEditControl Class

RichEditControl Members

DevExpress.XtraRichEdit Namespace