- 2 minutes to read
Any user action performed with the RichEdit control results in a command object being created and executed. All commands implemented in the Rich Edit control inherit from the Command object. Virtually every task can be accomplished via commands, such as inserting characters and pictures, selection, formatting, creating numbered lists, scrolling, etc.
The command's main method is Command.Execute. It accomplishes the task for which the command is implemented. Other properties, such as Command.Image, Command.LargeImage, Command.Description and Command.MenuCaption are used to visually and verbally represent a command. The following table shows the ToggleFontSuperscriptCommand command properties as an example.
|Large image||Small image||Menu caption||Description|
|Insert Rows Above||Add a new row directly above the selected row|
If the command is disabled for any reason, you can still use its Command.ForceExecute method to execute it.
A command may require additional data for its execution. Usually they are provided by the ICommandUIState.EditValue property.
You can modify the default functionality of virtually any command by substituting the RichEditCommandFactoryService, available via the IRichEditCommandFactoryService interface. See the IRichEditCommandFactoryService.CreateCommand topic for more information.
Most commands can be executed via keyboard shortcuts recognized by the RichEditControl. You can use the RichEditControl.RemoveShortcutKey and the RichEditControl.AssignShortcutKeyToCommand methods to modify shortcut keys assigned to commands.
You can use commands to replicate user activity on another RichEdit control, even on a different platform.
You should always create a new instance of a command before execution, otherwise you may experience undesired effects and unhandled exceptions.
Commands executed via the Bar (Ribbon) user interface can throw unhandled exceptions if a problem occurs. Consider the situation when a document is being saved to a locked or read-only file. To prevent application failure, subscribe to the RichEditControl.UnhandledException event and set the RichEditUnhandledExceptionEventArgs.Handled property to true.