Back to Devexpress

TextOptions.HotkeyPrefix Property

windowsforms-devexpress-dot-utils-dot-textoptions-25eb4076.md

latest7.2 KB
Original Source

TextOptions.HotkeyPrefix Property

Gets or sets whether to underline characters that are preceded with an ampersand symbol (&). This option is supported by a set of controls.

Namespace : DevExpress.Utils

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
[DefaultValue(HKeyPrefix.Default)]
[XtraSerializableProperty]
public virtual HKeyPrefix HotkeyPrefix { get; set; }
vb
<DefaultValue(HKeyPrefix.Default)>
<XtraSerializableProperty>
Public Overridable Property HotkeyPrefix As HKeyPrefix

Property Value

TypeDefaultDescription
HKeyPrefixDefault

A value that specifies how to interpret an ampersand character (&) in text.

|

Available values:

NameDescription
Default

Underline the character that is preceded by the ampersand symbol (&) when a user presses ALT.

| | None |

Show the ampersand symbol (&).

| | Show |

Underline the character preceded by the ampersand symbol (&).

| | Hide |

Do not underline the character that is preceded by the ampersand symbol (&).

|

Property Paths

You can access this nested property as listed below:

Object TypePath to HotkeyPrefix
AppearanceObject

.TextOptions .HotkeyPrefix

| | TextOptions |

.DefaultOptions .HotkeyPrefix

| | TextOptions |

.DefaultOptionsCenteredWithEllipsis .HotkeyPrefix

| | TextOptions |

.DefaultOptionsMultiLine .HotkeyPrefix

| | TextOptions |

.DefaultOptionsNoWrap .HotkeyPrefix

| | TextOptions |

.DefaultOptionsNoWrapEx .HotkeyPrefix

|

Remarks

For a set of controls, you can precede a specific character in the control’s text with an ampersand symbol (&) to create a shortcut (hotkey). All controls that support this feature underline target characters when a user presses the ALT key (the default behavior). The ALT+Character shortcut activates control functionality.

The following example demonstrates a sample button whose text is set to “&Run”. The ‘ALT+R’ shortcut will activate button action.

csharp
simpleButton1.Text = "&Run";
vb
SimpleButton1.Text = "&Run"

The following controls support the use of the ampersand symbol (&) to create hotkeys.

The HotkeyPrefix property allows you to choose one of display modes for characters preceded by an ampersand symbol (&):

  • Underline the next character when the ALT key is pressed.
  • Always underline the next character.
  • Do not underline the character.
  • Show the ampersand symbol.

The HotkeyPrefix property does not allow you to disable the hotkey functionality.

To disable the hotkey functionality and display the ampersand symbol as is, double the ampersand character in the control’s text.

csharp
simpleButton1.Text = "Fix&&Go";
vb
SimpleButton1.Text = "Fix&&Go"

When an AppearanceObject’s style setting (for example, BackColor , ForeColor , Font and TextOptions.HAlignment ) is set to a non-default value, the corresponding Options.Use… option (for instance, Options.UseBackColor , Options.UseForeColor , Options.UseFont and Options.UseTextOptions ) is automatically set to true in the following cases:

  • The AppearanceObject belongs to a control/component (or its element), and this control/component has been completely loaded (see the control’s IsLoading property to check the load status);
  • The AppearanceObject belongs to a grid column/band or tree list column/band, and the column/band belongs to a grid/tree list control;
  • The AppearanceObject is standalone, that is, it does not belong to any control or component.

In other cases, the Options.Use… options are not automatically enabled. You may need to enable these options manually for the style settings to be in effect.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the HotkeyPrefix property.

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-tabcontrol-paint-tab-header-text-vertically/CS/WindowsFormsApplication907/MySkinTabPainter.cs#L28

csharp
AppearanceObject a = pInfo.PaintAppearance;
System.Drawing.Text.HotkeyPrefix? hotKeyPrefixOverride = (a.TextOptions.HotkeyPrefix == HKeyPrefix.Default) || pInfo.UseHotkeyPrefixDrawModeOverride ?
    new System.Drawing.Text.HotkeyPrefix?(pInfo.HotkeyPrefixDrawModeOverride) : null;

See Also

TextOptions Class

TextOptions Members

DevExpress.Utils Namespace