RichEditControl.CreateCommand(RichEditCommandId) Method
Create a RichEditCommand object by the command identifier.
Namespace: DevExpress.XtraRichEdit
Assembly: DevExpress.XtraRichEdit.v18.1.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
commandId | RichEditCommandId | A RichEditCommandId structure member, which specifies a command. |
Returns
Type | Description |
---|---|
RichEditCommand | A RichEditCommand instance, representing a Rich Text Control command. |
Example
The following code creates commands by its RichEditCommandId using the RichEditControl.CreateCommand method. Each command is executed by calling the ForceExecute method which is specific for each command. The command UI state required for the ForceExecute method is obtained from the Command.CreateDefaultCommandUIState method.
The RichEditControl instance is passed to the BarItem.ItemClick event handler using the BarItem.Tag property.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/winforms-the-richeditcontrols-common-api-t210437
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();
}
Related GitHub Examples
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.