Back to Devexpress

RichEditControl.CreateCommand(RichEditCommandId) Method

windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-dot-createcommand-x28-devexpress-dot-xtrarichedit-dot-commands-dot-richeditcommandid-x29.md

latest6.0 KB
Original Source

RichEditControl.CreateCommand(RichEditCommandId) Method

Creates a RichEditCommand object by the command identifier.

Namespace : DevExpress.XtraRichEdit

Assembly : DevExpress.XtraRichEdit.v25.2.dll

NuGet Package : DevExpress.Win.RichEdit

Declaration

csharp
public virtual RichEditCommand CreateCommand(
    RichEditCommandId commandId
)
vb
Public Overridable Function CreateCommand(
    commandId As RichEditCommandId
) As RichEditCommand

Parameters

NameTypeDescription
commandIdRichEditCommandId

A RichEditCommandId structure member indicating a command.

|

Returns

TypeDescription
RichEditCommand

A Rich Text Control command.

|

Example

The following code calls the RichEditControl.CreateCommand method to create commands based on CapitalizeEachWordTextCase, ToggleFontBold, ChangeFontBackColor, and PrintPreview commands. Each command is executed by the ForceExecute method call. The Command.CreateDefaultCommandUIState method returns the command UI state.

All commands are executed an once on a button click.

View Example

csharp
static void buttonCustomAction_ItemClick_Commands(object sender, ItemClickEventArgs e) {

    RichEditControl richEdit = e.Item.Tag as RichEditControl;
    richEdit.SelectAll();

    RichEditCommand capCommand = richEdit.CreateCommand(RichEditCommandId.CapitalizeEachWordTextCase);
    capCommand.ForceExecute(capCommand.CreateDefaultCommandUIState());

    RichEditCommand boldCommand = richEdit.CreateCommand(RichEditCommandId.ToggleFontBold);
    boldCommand.ForceExecute(boldCommand.CreateDefaultCommandUIState());

    RichEditCommand changeFontColorCommand = richEdit.CreateCommand(RichEditCommandId.ChangeFontBackColor);
    DevExpress.Utils.Commands.ICommandUIState state = changeFontColorCommand.CreateDefaultCommandUIState();
    state.EditValue = Color.Yellow;
    changeFontColorCommand.ForceExecute(state);

    RichEditCommand previewCommand = richEdit.CreateCommand(RichEditCommandId.PrintPreview);
    previewCommand.ForceExecute(previewCommand.CreateDefaultCommandUIState());

    richEdit.DeselectAll();
}
vb
Private Shared Sub buttonCustomAction_ItemClick_Commands(ByVal sender As Object, ByVal e As ItemClickEventArgs)
    Dim richEdit As RichEditControl = TryCast(e.Item.Tag, RichEditControl)
    richEdit.SelectAll()

    Dim capCommand As RichEditCommand = richEdit.CreateCommand(RichEditCommandId.CapitalizeEachWordTextCase)
    capCommand.ForceExecute(capCommand.CreateDefaultCommandUIState())

    Dim boldCommand As RichEditCommand = richEdit.CreateCommand(RichEditCommandId.ToggleFontBold)
    boldCommand.ForceExecute(boldCommand.CreateDefaultCommandUIState())

    Dim changeFontColorCommand As RichEditCommand = richEdit.CreateCommand(RichEditCommandId.ChangeFontBackColor)
    Dim state As DevExpress.Utils.Commands.ICommandUIState = changeFontColorCommand.CreateDefaultCommandUIState()
    state.EditValue = System.Drawing.Color.Yellow
    changeFontColorCommand.ForceExecute(state)

    Dim previewCommand As RichEditCommand = richEdit.CreateCommand(RichEditCommandId.PrintPreview)
    previewCommand.ForceExecute(previewCommand.CreateDefaultCommandUIState())

    richEdit.DeselectAll()
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference 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.

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

csharp
RichEditCommand capCommand = richEdit.CreateCommand(RichEditCommandId.CapitalizeEachWordTextCase);
capCommand.ForceExecute(capCommand.CreateDefaultCommandUIState());

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

vb
Dim capCommand As RichEditCommand = richEdit.CreateCommand(RichEditCommandId.CapitalizeEachWordTextCase)
capCommand.ForceExecute(capCommand.CreateDefaultCommandUIState())

See Also

RichEditControl Class

RichEditControl Members

DevExpress.XtraRichEdit Namespace