Label.UseMnemonic Label.UseMnemonic Label.UseMnemonic Label.UseMnemonic Property

定義

取得或設定值,指出控制項是否將控制項的 Text 屬性中的連字號字元 (&),解譯為便捷鍵的前置字元。Gets or sets a value indicating whether the control interprets an ampersand character (&) in the control's Text property to be an access key prefix character.

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,否則,如果連字號字元顯示在控制項的文字中,則為 falsetrue if the label doesn't display the ampersand character and underlines the character after the ampersand in its displayed text and treats the underlined character as an access key; otherwise, false if the ampersand character is displayed in the text of the control. 預設為 trueThe default is true.

範例

下列程式碼範例示範如何建立Label具有3d 框線的控制項,以及ImageList使用和ImageIndex屬性顯示的影像。The following code example demonstrates how to create a Label control that has a three-dimensional border and an image displayed using the ImageList and ImageIndex properties. 控制項也有一個標題,其中指定了助憶鍵字元。The control also has a caption with a mnemonic character specified. 範例程式碼會使用PreferredHeightPreferredWidth Label屬性,適當地將控制項的大小調整為顯示的表單上。The example code uses the PreferredHeight and PreferredWidth properties to properly size the Label control on the form on which it is displayed. 這個範例要求ImageList已建立並命名為 imageList1,且已載入兩個映射。This example requires that an ImageList has been created and named imageList1 and that it has loaded two images. 此範例也會要求程式碼必須在將System.Drawing命名空間加入其程式碼的表單中。The example also requires that the code is within a form that has the System.Drawing namespace added to its code.

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

備註

如果屬性設定為true ,且助憶鍵字元(前面加上符號的字元Text )定義Label于的屬性中,請按 ALT + 助憶鍵字元,將焦點設定為UseMnemonic遵循定位Label順序中的。If the UseMnemonic property is set to true and a mnemonic character (a character preceded by the ampersand) is defined in the Text property of the Label, pressing ALT+ the mnemonic character sets the focus to the control that follows the Label in the tab order. 您可以使用這個屬性,為表單上的控制項提供適當的鍵盤導覽。You can use this property to provide proper keyboard navigation to the controls on your form.

適用於

另請參閱