Partager via


Label.UseMnemonic Propriété

Définition

Obtient ou définit une valeur indiquant si le contrôle interprète un caractère d’ampersand (&) dans la propriété du Text contrôle pour qu’il s’agisse d’un caractère de préfixe de clé d’accès.

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

Valeur de propriété

true si l’étiquette n’affiche pas le caractère ampersand et souligne le caractère après l’ampersand dans son texte affiché et traite le caractère souligné comme une touche d’accès ; sinon, false si l’ampersand caractère est affiché dans le texte du contrôle. La valeur par défaut est true.

Exemples

L’exemple de code suivant montre comment créer un Label contrôle qui a une bordure tridimensionnelle et une image affichée à l’aide des propriétés et ImageIndex des ImageList propriétés. Le contrôle a également une légende avec un caractère mnemonique spécifié. L’exemple de code utilise les propriétés et PreferredWidth les PreferredHeight propriétés pour dimensionner correctement le Label contrôle sur le formulaire sur lequel il est affiché. Cet exemple nécessite qu’une ImageList image a été créée et nommée imageList1 et qu’elle ait chargé deux images. L’exemple nécessite également que le code se trouve dans un formulaire dont l’espace System.Drawing de noms est ajouté à son 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

Remarques

Si la UseMnemonic propriété est définie true sur et qu’un caractère mnnémonique (un caractère précédé de l’ampersand) est défini dans la propriété de l’objet TextLabel, en appuyant sur ALT+ le caractère mnemonique définit le focus sur le contrôle qui suit l’ordre Label de tabulation. Vous pouvez utiliser cette propriété pour fournir une navigation au clavier appropriée aux contrôles de votre formulaire.

S’applique à

Voir aussi