共用方式為


StringFormat.HotkeyPrefix 屬性

定義

取得或設定這個 StringFormat 物件的 HotkeyPrefix 物件。

public:
 property System::Drawing::Text::HotkeyPrefix HotkeyPrefix { System::Drawing::Text::HotkeyPrefix get(); void set(System::Drawing::Text::HotkeyPrefix value); };
public System.Drawing.Text.HotkeyPrefix HotkeyPrefix { get; set; }
member this.HotkeyPrefix : System.Drawing.Text.HotkeyPrefix with get, set
Public Property HotkeyPrefix As HotkeyPrefix

屬性值

這個 StringFormat 物件的 HotkeyPrefix 物件,預設為 None

範例

下列程式代碼範例示範如何使用 屬性設定鍵盤快捷方式 HotkeyPrefix 。 它也會示範如何使用 FromSystemColor 方法。 若要執行此範例,請將程式代碼貼到表單中、處理表單的事件 Paint ,並呼叫下列方法,並將 e 傳遞為 PaintEventArgs

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.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 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

備註

在圖形使用者介面中,熱鍵是單字中的加底線字母, (通常與另一個按鍵結合,例如 Alt 鍵) ,您可以按下鍵盤來啟動該字組所代表的功能。

適用於