StringFormat.HotkeyPrefix Property


Gets or sets the HotkeyPrefix object for this StringFormat object.

Namespace:   System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public HotkeyPrefix HotkeyPrefix { get; set; }

Property Value

Type: System.Drawing.Text.HotkeyPrefix

The HotkeyPrefix object for this StringFormat object, the default is None.

In a graphical user interface, a hot key is the underlined letter in a word (usually combined with another key, such as the Alt key) that you can press on the keyboard to activate the functionality that the word represents.

The following code example shows how to set a keyboard shortcut using the HotkeyPrefix property. It also demonstrates how to use the FromSystemColor method. To run this example, paste the code into a form, handle the form's Paint event and call the following method, passing e as PaintEventArgs.

private void ShowHotKey(PaintEventArgs e)

    // Declare the string with a keyboard shortcut.
    string text = "&Click Here";

    // Declare a new StringFormat.
    StringFormat format = new StringFormat();

    // Set the HotkeyPrefix property.
    format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;

    // Draw the string.
    Brush theBrush = 

    e.Graphics.DrawString(text, this.Font, theBrush, 30, 40, format);

.NET Framework
Available since 1.1
Return to top