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 элемент управления с трехмерной границей и изображением, отображаемым с помощью ImageList свойств и ImageIndex . Элемент управления также имеет подпись с указанным мнемоническим символом. В примере кода свойства и PreferredWidth используются PreferredHeight для правильного 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 и в свойстве Labelопределен Text мнемонический символ (символ, предшествующий амперсанду), нажатие клавиши ALT+ мнемонический символ устанавливает фокус на элемент управления, следующий за Label , в порядке табуляции. Это свойство можно использовать для обеспечения правильной навигации с помощью клавиатуры по элементам управления в форме.

Применяется к

См. также раздел