Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
  • The page you are viewing does not exist in the .NET Standard 2.0+ platform documentation. This link will take you to the parent topic of the current section.

IRichEditCommandFactoryService Interface

Defines a service which is used to create RichEdit commands.

Namespace: DevExpress.XtraRichEdit.Services

Assembly: DevExpress.RichEdit.v19.1.Core.dll

Declaration

[ComVisible(true)]
public interface IRichEditCommandFactoryService

Remarks

The following code implements the IRichEditCommandFactoryService descendant which generates customized SaveDocumentCommand and SaveDocumentAsCommand commands. The command descendants override the ExecuteCore methods to display a message after a document has been saved. The IsModified internal property indicates unsaved changes in the document. If this property is not changed to false after saving a document, it signals that the save action failed.

Public Class CustomRichEditCommandFactoryService
    Implements IRichEditCommandFactoryService
    Private ReadOnly service As IRichEditCommandFactoryService
    Private ReadOnly control As RichEditControl

    Public Sub New(ByVal control As RichEditControl, ByVal service As IRichEditCommandFactoryService)
        DevExpress.Utils.Guard.ArgumentNotNull(control, "control")
        DevExpress.Utils.Guard.ArgumentNotNull(service, "service")
        Me.control = control
        Me.service = service
    End Sub

    Public Function CreateCommand(ByVal id As RichEditCommandId) As RichEditCommand Implements IRichEditCommandFactoryService.CreateCommand
        If id.Equals(RichEditCommandId.FileSaveAs) Then
            Return New CustomSaveDocumentAsCommand(control)
        End If
        If id.Equals(RichEditCommandId.FileSave) Then
            Return New CustomSaveDocumentCommand(control)
        End If
        Return service.CreateCommand(id)
    End Function
End Class

Public Class CustomSaveDocumentCommand
    Inherits SaveDocumentCommand
    Public Sub New(ByVal richEdit As IRichEditControl)
        MyBase.New(richEdit)
    End Sub

    Protected Overrides Sub ExecuteCore()
        MyBase.ExecuteCore()
        If (Not DocumentServer.Modified) Then
            MessageBox.Show("Document is saved successfully")
        End If
    End Sub
End Class

Public Class CustomSaveDocumentAsCommand
    Inherits SaveDocumentAsCommand
    Public Sub New(ByVal richEdit As IRichEditControl)
        MyBase.New(richEdit)
    End Sub

    Protected Overrides Sub ExecuteCore()
        DocumentServer.Modified = True
        MyBase.ExecuteCore()
        If (Not DocumentServer.Modified) Then
            MessageBox.Show("Document is saved successfully")
        End If
    End Sub
End Class

The following code replaces the IRichEditCommandFactoryService service with its customized descendant.

richEditControl.Text = "A message box is displayed when a document is saved on the 'Save' or 'Save As' button click since custom commands are used"
Dim commandFactory = New CustomRichEditCommandFactoryService(richEditControl, richEditControl.GetService(Of IRichEditCommandFactoryService)())
richEditControl.ReplaceService(Of IRichEditCommandFactoryService)(commandFactory)
See Also