Label.UseMnemonic Propriedade

Definição

Obtém ou define um valor que indica se o controle interpreta o caractere & (E comercial) na propriedade Text do controle como um caractere de prefixo de chave de acesso.

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

Valor da propriedade

true se o rótulo não exibir o caractere E comercial, sublinhar o caractere após o E comercial em seu texto exibido e tratar o caractere sublinhado como uma chave de acesso. Caso contrário, false se o caractere E comercial for exibido no texto do controle. O padrão é true.

Exemplos

O exemplo de código a seguir demonstra como criar um Label controle que tem uma borda tridimensional e uma imagem exibida usando as ImageList propriedades e ImageIndex . O controle também tem um legenda com um caractere mnemônico especificado. O código de exemplo usa as PreferredHeight propriedades e PreferredWidth para dimensionar corretamente o Label controle no formulário no qual ele é exibido. Este exemplo requer que um ImageList tenha sido criado e nomeado imageList1 e que tenha carregado duas imagens. O exemplo também requer que o código esteja dentro de um formulário que tenha o System.Drawing namespace adicionado ao seu código.

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

Comentários

Se a UseMnemonic propriedade for definida true como e um caractere mnemônico (um caractere precedido pelo e comercial) for definido na Text propriedade do Label, pressionar ALT+ o caractere mnemônico definirá o foco para o controle que segue o Label na ordem de tabulação. Você pode usar essa propriedade para fornecer navegação de teclado adequada para os controles em seu formulário.

Aplica-se a

Confira também