StringFormat.HotkeyPrefix 属性

获取或设置此 StringFormat 对象的 HotkeyPrefix 对象。

**命名空间:**System.Drawing
**程序集:**System.Drawing(在 system.drawing.dll 中)

语法

声明
Public Property HotkeyPrefix As HotkeyPrefix
用法
Dim instance As StringFormat
Dim value As HotkeyPrefix

value = instance.HotkeyPrefix

instance.HotkeyPrefix = value
public HotkeyPrefix HotkeyPrefix { get; set; }
public:
property HotkeyPrefix HotkeyPrefix {
    HotkeyPrefix get ();
    void set (HotkeyPrefix value);
}
/** @property */
public HotkeyPrefix get_HotkeyPrefix ()

/** @property */
public void set_HotkeyPrefix (HotkeyPrefix value)
public function get HotkeyPrefix () : HotkeyPrefix

public function set HotkeyPrefix (value : HotkeyPrefix)

属性值

StringFormat 对象的 HotkeyPrefix 对象。

备注

在图形用户界面中,热键是单词中带下划线的字母(通常与 Alt 键等其他键组合),可以按键盘上的这个字母来激活该单词所代表的功能。

示例

下面的代码示例演示如何使用 HotkeyPrefix 属性设置键盘快捷键。它还演示如何使用 FromSystemColor 方法。若要运行此示例,请将代码粘贴到一个窗体中,处理该窗体的 Paint 事件并调用下面的方法,将 e 作为 PaintEventArgs 传递。

Private Sub ShowHotKey(ByVal e As PaintEventArgs)

    ' Declare the string with keyboard shortcut.
    Dim text As String = "&Click Here"

    ' Declare a new StringFormat.
    Dim format As New StringFormat

    ' Set the HotkeyPrefix property.
    format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show

    ' Draw the string.
    Dim theBrush As Brush = _
        SystemBrushes.FromSystemColor(SystemColors.Highlight)
    e.Graphics.DrawString(text, Me.Font, theBrush, 30, 40, format)
End Sub
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 = 
        SystemBrushes.FromSystemColor(SystemColors.Highlight);

    e.Graphics.DrawString(text, this.Font, theBrush, 30, 40, format);
}
private:
   void ShowHotKey( PaintEventArgs^ e )
   {
      // Declare the string with a keyboard shortcut.
      String^ text = "&Click Here";

      // Declare a new StringFormat.
      StringFormat^ format = gcnew StringFormat;

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

      // Draw the string.
      Brush^ theBrush = SystemBrushes::FromSystemColor( SystemColors::Highlight );
      e->Graphics->DrawString( text, this->Font, theBrush, 30, 40, format );
   }
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.set_HotkeyPrefix(System.Drawing.Text.HotkeyPrefix.Show);

    // Draw the string.
    Brush theBrush = SystemBrushes.FromSystemColor(
        SystemColors.get_Highlight());

    e.get_Graphics().DrawString(text, this.get_Font(), theBrush, 30, 40, 
        format);
} //ShowHotKey

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

StringFormat 类
StringFormat 成员
System.Drawing 命名空间