Bagikan melalui


Label.UseMnemonic Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan apakah kontrol menginterpretasikan karakter ampersand (&) di properti kontrol Text untuk menjadi karakter awalan kunci akses.

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

Nilai Properti

true jika label tidak menampilkan karakter ampersand dan menggarisbawahi karakter setelah ampersand dalam teks yang ditampilkan dan memperlakukan karakter bergaris bawah sebagai kunci akses; jika tidak, false jika karakter ampersand ditampilkan dalam teks kontrol. Default adalah true.

Contoh

Contoh kode berikut menunjukkan cara membuat Label kontrol yang memiliki batas tiga dimensi dan gambar yang ditampilkan menggunakan ImageList properti dan ImageIndex . Kontrol ini juga memiliki caption dengan karakter mnemonik yang ditentukan. Kode contoh menggunakan PreferredHeight properti dan PreferredWidth untuk mengukur Label kontrol dengan benar pada formulir tempat kode tersebut ditampilkan. Contoh ini mengharuskan telah ImageList dibuat dan diberi nama imageList1 dan telah memuat dua gambar. Contoh ini juga mengharuskan kode berada dalam formulir yang memiliki namespace layanan System.Drawing yang ditambahkan ke kodenya.

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

Keterangan

UseMnemonic Jika properti diatur ke true dan karakter mnemonik (karakter yang didahului oleh ampersand) didefinisikan dalam Text properti , Labelmenekan ALT + karakter mnemonik mengatur fokus ke kontrol yang mengikuti Label dalam urutan tab. Anda dapat menggunakan properti ini untuk menyediakan navigasi keyboard yang tepat ke kontrol pada formulir Anda.

Berlaku untuk

Lihat juga