Freigeben über


Label.UseMnemonic-Eigenschaft

Ruft einen Wert ab, der angibt, ob das Steuerelement ein kaufmännisches Und-Zeichen (&) in der Text-Eigenschaft des Steuerelements als Präfix für eine Zugriffstaste interpretiert, oder legt diesen fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Property UseMnemonic As Boolean
'Usage
Dim instance As Label
Dim value As Boolean

value = instance.UseMnemonic

instance.UseMnemonic = value
public bool UseMnemonic { get; set; }
public:
property bool UseMnemonic {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_UseMnemonic ()

/** @property */
public void set_UseMnemonic (boolean value)
public function get UseMnemonic () : boolean

public function set UseMnemonic (value : boolean)

Eigenschaftenwert

true, wenn das Label das kaufmännische Und-Zeichen nicht darstellt und das Zeichen nach dem kaufmännischen Und-Zeichen unterstreicht und das unterstrichene Zeichen als Zugriffstaste behandelt. Andernfalls false, wenn das kaufmännische Und-Zeichen im Text des Steuerelements dargestellt wird. Der Standardwert ist true.

Hinweise

Wenn die UseMnemonic-Eigenschaft auf true festgelegt ist und in der Text-Eigenschaft von Label ein mnemonisches Zeichen (ein Zeichen, dem ein kaufmännisches Und-Zeichen (&) vorangeht) definiert wurde, geht der Fokus in der Aktivierreihenfolge auf das auf Label folgende Steuerelement über, wenn die Kombination aus ALT und einem mnemonischen Zeichen gedrückt wird. Diese Eigenschaft ermöglicht das Navigieren mit der Tastatur im Formular.

Beispiel

Im folgenden Beispiel wird veranschaulicht, wie mithilfe der Eigenschaften ImageList und ImageIndex ein Label-Steuerelement mit einem dreidimensionalen Rahmen und einem Bild erstellt wird. Das Steuerelement verfügt außerdem über eine Beschriftung mit einem angegebenen mnemonischen Zeichen. Im Beispielcode werden die PreferredHeight-Eigenschaft und die PreferredWidth-Eigenschaft dazu verwendet, die Größe des Label-Steuerelements in dem Formular anzupassen, auf dem es angezeigt wird. Für dieses Beispiel muss eine ImageList mit dem Namen imageList1 erstellt werden, in die zwei Bilder geladen werden. Weiterhin ist erforderlich, dass sich der Code in einem Formular befindet, in dessen Code der System.Drawing-Namespace eingebunden ist.

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
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:
   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.set_BorderStyle(System.Windows.Forms.BorderStyle.Fixed3D);
    // Set the ImageList to use for displaying an image.
    label1.set_ImageList(imageList1);
    // Use the second image in imageList1.
    label1.set_ImageIndex(1);
    // Align the image to the top left corner.
    label1.set_ImageAlign(ContentAlignment.TopLeft);
    // Specify that the text can display mnemonic characters.
    label1.set_UseMnemonic(true);
    // Set the text of the control and specify a mnemonic character.
    label1.set_Text("First &Name:");
    /* Set the size of the control based on the PreferredHeight
       and PreferredWidth values. */
    label1.set_Size(new Size(label1.get_PreferredWidth(), 
        label1.get_PreferredHeight()));
    //...Code to add the control to the form...
} //CreateMyLabel 
public function CreateMyLabel()
{
   // Create an instance of a Label.
   var label1 : Label = 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 System.Drawing.Size (label1.PreferredWidth, label1.PreferredHeight);

   //...Code to add the control to the form...
}

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

Label-Klasse
Label-Member
System.Windows.Forms-Namespace
Control.Text-Eigenschaft