Skip to main content

RichEditControl.CreateCommand(RichEditCommandId) Method

Creates a RichEditCommand object by the command identifier.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.XtraRichEdit.v22.2.dll

NuGet Package: DevExpress.Win.RichEdit

Declaration

public virtual RichEditCommand CreateCommand(
    RichEditCommandId commandId
)

Parameters

Name Type Description
commandId RichEditCommandId

A RichEditCommandId structure member indicating a command.

Returns

Type Description
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

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();
}
See Also