windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-dot-assignshortcutkeytocommand-x28-system-dot-windows-dot-forms-dot-keys-system-dot-windows-dot-forms-dot-keys-devexpress-dot-xtrarichedit-dot-commands-dot-richeditcommandid-x29.md
Assigns a shortcut key to a command. The shortcut key is available for all RichEdit views.
Namespace : DevExpress.XtraRichEdit
Assembly : DevExpress.XtraRichEdit.v25.2.dll
NuGet Package : DevExpress.Win.RichEdit
public void AssignShortcutKeyToCommand(
Keys key,
Keys modifier,
RichEditCommandId commandId
)
Public Sub AssignShortcutKeyToCommand(
key As Keys,
modifier As Keys,
commandId As RichEditCommandId
)
| Name | Type | Description |
|---|---|---|
| key | Keys |
A Keys enumeration member specifying a key to assign.
| | modifier | Keys |
A Keys enumeration member specifying a modifier key.
| | commandId | RichEditCommandId |
A RichEditCommandId enumeration member specifying a command.
|
To remove a command shortcut, use the RichEditControl.RemoveShortcutKey method.
The following code assigns Ctrl+G shortcut to ToggleShowWhitespaceCommand and removes predefined Ctrl+N shortcut so that it is no longer in use.
using System.Windows.Forms;
richEditControl.Text = "Use 'Ctrl+G' shortcut to show/hide whitespace characters";
richEditControl.Text += "\r\nYou can no longer use the 'Ctrl+N' shortcut to create a new document.";
richEditControl.AssignShortcutKeyToCommand(Keys.Control, Keys.G, RichEditCommandId.ToggleShowWhitespace);
richEditControl.RemoveShortcutKey(Keys.Control, Keys.N);
Imports System.Windows.Forms
richEditControl.Text = "Use 'Ctrl+G' shortcut to show/hide whitespace characters"
richEditControl.Text += Constants.vbCrLf & "You can no longer use the 'Ctrl+N' shortcut to create a new document"
richEditControl.AssignShortcutKeyToCommand(Keys.Control, Keys.G, RichEditCommandId.ToggleShowWhitespace)
richEditControl.RemoveShortcutKey(Keys.Control, Keys.N)
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AssignShortcutKeyToCommand(Keys, Keys, 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#L550
richEditControl.Text += "\r\nA new document can not be created by pressing 'Ctrl+N' shortcut since this shortcut is disabled";
richEditControl.AssignShortcutKeyToCommand(System.Windows.Forms.Keys.Control, System.Windows.Forms.Keys.G, RichEditCommandId.ToggleShowWhitespace);
richEditControl.RemoveShortcutKey(System.Windows.Forms.Keys.Control, System.Windows.Forms.Keys.N);
winforms-richeditcontrol-common-api/VB/RichEditAPISample/CodeExamples/RichEditControlActions.vb#L560
richEditControl.Text += Constants.vbCrLf & "A new document can't be created by pressing 'Ctrl+N' shortcut since this shortcut is disabled"
richEditControl.AssignShortcutKeyToCommand(System.Windows.Forms.Keys.Control, System.Windows.Forms.Keys.G, RichEditCommandId.ToggleShowWhitespace)
richEditControl.RemoveShortcutKey(System.Windows.Forms.Keys.Control, System.Windows.Forms.Keys.N)
See Also