共用方式為


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,否則,如果連字號字元顯示在控制項的文字中,則為 false。 預設為 true

範例

下列程式代碼範例示範如何建立 Label 具有三維框線的控件,以及使用 ImageListImageIndex 屬性顯示的影像。 控制件也有指定助記鍵字元的 標題。 此範例程式代碼會使用 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

備註

UseMnemonic如果 屬性設定true為 ,且助記鍵字元 (前面加上 ampersand) 的字元定義於 的 屬性LabelText,按 ALT+ 鍵鍵字元會將焦點設定為定位順序中 後面Label之 的控件。 您可以使用此屬性,為表單上的控制項提供適當的鍵盤流覽。

適用於

另請參閱