Label.UseMnemonic Proprietà

Definizione

Ottiene o imposta un valore che indica se il controllo interpreta un carattere amperand (&) nella proprietà del Text controllo per essere un carattere di prefisso chiave di accesso.

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

Valore della proprietà

true se l'etichetta non visualizza il carattere amperand e sottolinea il carattere dopo l'amperatore nel testo visualizzato e considera il carattere sottolineato come chiave di accesso; in caso contrario, false se il carattere amperand viene visualizzato nel testo del controllo. Il valore predefinito è true.

Esempio

Nell'esempio di codice seguente viene illustrato come creare un Label controllo con un bordo tridimensionale e un'immagine visualizzata usando le ImageList proprietà e ImageIndex . Il controllo ha anche un didascalia con un carattere mnemonic specificato. Il codice di esempio usa le PreferredHeight proprietà e PreferredWidth per ridimensionare correttamente il Label controllo nel modulo in cui viene visualizzato. Questo esempio richiede che sia ImageList stato creato e denominato imageList1 e che abbia caricato due immagini. L'esempio richiede inoltre che il codice si trova all'interno di un modulo con lo System.Drawing spazio dei nomi aggiunto al codice.

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

Commenti

Se la UseMnemonic proprietà è impostata su true e un carattere mnemonic (un carattere preceduto dall'amperand) viene definito nella Text proprietà Label, premendo ALT+ il carattere mnemonic imposta lo stato attivo sul controllo che segue l'oggetto Label nell'ordine di tabulazione. È possibile usare questa proprietà per fornire lo spostamento della tastiera appropriato ai controlli nel modulo.

Si applica a

Vedi anche