Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
    Overview
   [Expand]Getting Started
   [Collapse]Fundamentals
    [Expand]RichEditControl
    [Expand]Document
     Supported Document Formats
    [Expand]Fields
     Commands
     Services
     Layout API
     Product Class Structure
     Default Keyboard Shortcuts
     Measure Units
     HTML Tag Interpretation
   [Expand]Concepts
   [Expand]Visual Elements
   [Expand]Examples
   [Expand]Member Tables
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Commands

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 InsertTableRowAboveCommand command properties as an example.

Command

Large image

Small image

Menu caption

Description

InsertTableRowAboveCommand

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.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T210437.

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.

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 RichEditControl. A list of default command shortcuts is shown in the Default Keyboard Shortcuts document. 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 can bind a command to virtually any UI element. This technique is illustrated in the How to: Bind a Command to a Button document.

Note

You should always create a new instance of a command before execution, otherwise you may experience undesired effects and unhandled exceptions.

Note

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.

How would you rate this topic?​​​​​​​