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.CreateCommand(RichEditCommandId) Method

Creates a command by its ID.

Namespace: DevExpress.XtraRichEdit.Services

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

Declaration

RichEditCommand CreateCommand(
    RichEditCommandId id
)

Parameters

Name Type Description
id RichEditCommandId

A RichEditCommandId member specifying a command to create.

Returns

Type Description
RichEditCommand

An XtraRichEdit command object.

Remarks

Implement the CreateCommand method in the custom service which substitutes the default command factory service to replace a built-in command in the XtraRichEdit.

Example

This sample code enables you to substitute a default SaveDocumentCommand with a CustomSaveFileCommand class object, providing additional functionality.

Public NotInheritable Class MyFactoryHelper

    Private Sub New()
    End Sub

    Public Shared Sub SetMyNewCommandFactory(ByVal control As RichEditControl)
        Dim myCommandFactory = New CustomRichEditCommandFactoryService(control, control.GetService(Of IRichEditCommandFactoryService)())
        control.ReplaceService(Of IRichEditCommandFactoryService)(myCommandFactory)
    End Sub
End Class

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)
        Me.control = control
        Me.service = service
    End Sub
    Public Function CreateCommand(ByVal id As RichEditCommandId) As RichEditCommand Implements IRichEditCommandFactoryService.CreateCommand
        If id = 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 control As IRichEditControl)
        MyBase.New(control)
    End Sub
    Protected Overrides Sub UpdateUIStateCore(ByVal state As ICommandUIState)
        MyBase.UpdateUIStateCore(state)
        ' Disable the command if the document has less than 5 paragraphs.
        state.Enabled = Control.Document.Paragraphs.Count > 5
    End Sub

    Protected Overrides Sub ExecuteCore()
        ' Cancel execution if the document contains less than 7 paragraphs.
        If Control.Document.Paragraphs.Count > 7 Then
            MyBase.ExecuteCore()
        Else
            MessageBox.Show("You should type at least 7 paragraphs to be able to save the document.", "Please be creative", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub
End Class

The following code snippets (auto-collected from DevExpress Examples) contain references to the CreateCommand(RichEditCommandId) 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.

See Also