Skip to main content
A newer version of this page is available. .

RichEditControl.AutoCorrect Event

Fires when text is typed in the control.

Namespace: DevExpress.Xpf.RichEdit

Assembly: DevExpress.Xpf.RichEdit.v20.2.dll

NuGet Packages: DevExpress.WindowsDesktop.Wpf.RichEdit, DevExpress.Wpf.RichEdit

Declaration

public event AutoCorrectEventHandler AutoCorrect

Event Data

The AutoCorrect event's data class is AutoCorrectEventArgs. The following properties provide information specific to this event:

Property Description
AutoCorrectInfo Gets or sets the AutoCorrectInfo object that provides methods to analyze input text and contains a replacement object.

The event data class exposes the following methods:

Method Description
CreateAutoCorrectInfo() Allows you to create a new AutoCorrectInfo instance for use within the event handler.

Remarks

Handle the AutoCorrect event to implement complex replacements as you type.

The RichEditControl.AutoCorrect event is handled to replace the typed $ symbol with a picture of a dollar, and substitute the text enclosed in percent symbols with custom content.

To accomplish this task, a document text obtained via the AutoCorrectEventArgs.AutoCorrectInfo property is amended by expanding its left boundary using the AutoCorrectInfo.DecrementStartPosition method, until a special symbol or a word separator symbol is found. If a resulting string meets certain conditions, such as whether it is a dollar sign or a %date% string, a replacement object is passed to the document via the AutoCorrectInfo.ReplaceWith property. A replacement object can be a string or an image.

View Example

Private Sub richEditControl1_AutoCorrect(ByVal sender As Object, ByVal e As DevExpress.XtraRichEdit.AutoCorrectEventArgs)
    Dim info As AutoCorrectInfo = e.AutoCorrectInfo
    e.AutoCorrectInfo = Nothing

    If info.Text.Length <= 0 Then
        Return
    End If
    Do
        If Not info.DecrementStartPosition() Then
            Return
        End If

        If IsSeparator(info.Text(0)) Then
            Return
        End If

        If info.Text(0) = "$"c Then
            info.ReplaceWith = CreateImageFromResx("dollar_pic.png")
            e.AutoCorrectInfo = info
            Return
        End If

        If info.Text(0) = "%"c Then
            Dim replaceString As String = CalculateFunction(info.Text)
            If Not String.IsNullOrEmpty(replaceString) Then
                info.ReplaceWith = replaceString
                e.AutoCorrectInfo = info
            End If
            Return
        End If
    Loop
End Sub

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

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.

See Also