共用方式為


Label.UseMnemonic 屬性

定義

取得或設定一個值,指示控制項是否將控制項屬性中的 Text &符號(&)解釋為存取鍵前綴字元。

public:
 property bool UseMnemonic { bool get(); void set(bool value); };
public bool UseMnemonic { get; set; }
member this.UseMnemonic : bool with get, set
Public Property UseMnemonic As Boolean

屬性值

如果標籤沒有顯示 & 字元,且在顯示文字中將該字元加底線,且將底線字元視為存取鍵;否則, 若控制項文字中顯示 & 符號。 預設值為 true

範例

以下程式碼範例示範如何建立Label一個控制項,該控制項有三維邊界,並以 和 ImageIndex 屬性顯示ImageList影像。 控制鍵上還有說明文字,並指定助記字元。 範例程式碼使用 和 PreferredHeightPreferredWidth 屬性來正確調整顯示表單上的控制項大小 Label 。 此範例需要 ImageList 已建立並命名為 imageList1,且載入兩張圖片。 範例還要求程式碼必須位於一個已加入 System.Drawing 命名空間的表單中。

public:
   void CreateMyLabel()
   {
      // Create an instance of a Label.
      Label^ label1 = gcnew Label;
      
      // Set the border to a three-dimensional border.
      label1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
      // Set the ImageList to use for displaying an image.
      label1->ImageList = imageList1;
      // Use the second image in imageList1.
      label1->ImageIndex = 1;
      // Align the image to the top left corner.
      label1->ImageAlign = ContentAlignment::TopLeft;
      
      // Specify that the text can display mnemonic characters.
      label1->UseMnemonic = true;
      // Set the text of the control and specify a mnemonic character.
      label1->Text = "First &Name:";
      
      /* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
      label1->Size = System::Drawing::Size( label1->PreferredWidth, label1->PreferredHeight );
      
      //...Code to add the control to the form...
   }
public void CreateMyLabel()
{
   // Create an instance of a Label.
   Label label1 = new Label();

   // Set the border to a three-dimensional border.
   label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
   // Set the ImageList to use for displaying an image.
   label1.ImageList = imageList1;
   // Use the second image in imageList1.
   label1.ImageIndex = 1;
   // Align the image to the top left corner.
   label1.ImageAlign = ContentAlignment.TopLeft;

   // Specify that the text can display mnemonic characters.
   label1.UseMnemonic = true;
   // Set the text of the control and specify a mnemonic character.
   label1.Text = "First &Name:";
   
   /* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
   label1.Size = new Size (label1.PreferredWidth, label1.PreferredHeight);

   //...Code to add the control to the form...
}
Public Sub CreateMyLabel()
    ' Create an instance of a Label.
    Dim label1 As New Label()
       
    ' Set the border to a three-dimensional border.
    label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    ' Set the ImageList to use for displaying an image.
    label1.ImageList = imageList1
    ' Use the second image in imageList1.
    label1.ImageIndex = 1
    ' Align the image to the top left corner.
    label1.ImageAlign = ContentAlignment.TopLeft
     
    ' Specify that the text can display mnemonic characters.
    label1.UseMnemonic = True
    ' Set the text of the control and specify a mnemonic character.
    label1.Text = "First &Name:"
       
    ' Set the size of the control based on the PreferredHeight and PreferredWidth values. 
    label1.Size = New Size(label1.PreferredWidth, label1.PreferredHeight)

    '...Code to add the control to the form...
End Sub

備註

屬性設為 ,且在 屬性中定義了助記字元(前置 & 符號的字元),按下 ALT+ 助記字元,則將焦點設定在 以 的 控制項後,按制表順序。 你可以利用這個特性,為表單上的控制項提供正確的鍵盤導航。

適用於

另請參閱