Bagikan melalui


Label.ImageAlign Properti

Definisi

Mendapatkan atau mengatur perataan gambar yang ditampilkan dalam kontrol.

public:
 property System::Drawing::ContentAlignment ImageAlign { System::Drawing::ContentAlignment get(); void set(System::Drawing::ContentAlignment value); };
public System.Drawing.ContentAlignment ImageAlign { get; set; }
member this.ImageAlign : System.Drawing.ContentAlignment with get, set
Public Property ImageAlign As ContentAlignment

Nilai Properti

Salah ContentAlignment satu nilai. Defaultnya adalah ContentAlignment.MiddleCenter.

Pengecualian

Nilai yang ditetapkan bukan salah ContentAlignment satu nilai.

Contoh

Contoh kode berikut menunjukkan cara membuat Label kontrol yang memiliki batas tiga dimensi dan gambar yang ditampilkan menggunakan ImageList properti dan ImageIndex . Kontrol juga memiliki keterangan dengan karakter mnemonic yang ditentukan. Contoh kode menggunakan PreferredHeight properti dan PreferredWidth untuk mengukur Label kontrol dengan benar pada formulir tempat kode 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 System.Drawing namespace layanan 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

Properti ini memungkinkan Anda menyelaraskan gambar dalam batas Label kontrol untuk memastikan bahwa gambar ditampilkan dengan benar. Anda dapat menambahkan gambar ke Label menggunakan properti atau ImageList properti dan ImageIndexImage . Gambar yang ditampilkan dalam kontrol tidak dapat direntangkan atau diciutkan untuk mengisi kontrol jika kontrol lebih besar atau lebih kecil dari gambar.

Berlaku untuk

Lihat juga