Label.ImageIndex Özellik

Tanım

üzerinde Labelgörüntülenen görüntünün dizin değerini alır veya ayarlar.

public:
 property int ImageIndex { int get(); void set(int value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))]
public int ImageIndex { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))>]
member this.ImageIndex : int with get, set
Public Property ImageIndex As Integer

Özellik Değeri

Denetimin ImageList (özelliğine ImageList atanır) görüntünün bulunduğu konumu temsil eden sıfır tabanlı dizin. Varsayılan değer -1'dir.

Öznitelikler

Özel durumlar

value -1'den küçük.

Örnekler

Aşağıdaki kod örneği, ve özellikleri kullanılarak görüntülenen üç boyutlu kenarlık ve görüntüye sahip bir denetimin ImageListImageIndex nasıl oluşturulacağını Label gösterir. Denetimin ayrıca, belirtilen bir anımsatıcı karakteri olan bir resim yazısı vardır. Örnek kod, denetimi görüntülendiği formda düzgün boyutlandırmak Label için ve PreferredWidth özelliklerini kullanırPreferredHeight. Bu örnek, bir ImageList oluşturulmuş ve imageList1 adlı bir ve iki görüntü yüklemiş olmasını gerektirir. Örnek ayrıca kodun ad alanının koduna System.Drawing eklendiği bir formda olmasını gerektirir.

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

Açıklamalar

ImageIndex ve ImageList özellikleri özelliğiyle aynı anda Image kullanılamaz. ImageIndex Bir görüntüyü görüntülemek için özellik ve ImageList özellikler kullanıldığında, Image özelliği otomatik olarak olarak nullayarlanır.

ImageKey ve ImageIndex birbirini dışlar, yani biri ayarlanırsa, diğeri geçersiz bir değere ayarlanır ve yoksayılır. Özelliğini ayarlarsanız ImageKey , ImageIndex özelliği otomatik olarak -1 olarak ayarlanır. Alternatif olarak, özelliğini ayarlarsanız ImageIndex , ImageKey otomatik olarak boş bir dize ("") olarak ayarlanır.

ImageList Özellik değeri olarak değiştirilirsenullImageIndex, özellik varsayılan değeri olan -1 değerini döndürür. Ancak, atanan ImageIndex değer dahili olarak tutulur ve özelliğe başka bir ImageList nesne atandığında ImageList kullanılır. Özelliğe atanan yeni ImageList özelliğinImageList, özellik değerine atanan ImageIndex değerden küçük veya buna eşit bir ImageList.ImageCollection.Count özellik değeri varsa (koleksiyonun sıfır tabanlı bir dizin olmasını hesaba katmak için), ImageIndex özellik değeri özellik değerinden Count bir küçüke ayarlanır. Örneğin, üç görüntüsü olan ImageList ve ImageIndex özelliği 2 olarak ayarlanmış bir düğme denetimini düşünün. Düğmeye yalnızca iki resim içeren bir yeni ImageList atanırsa, ImageIndex değer 1 olarak değişir.

Şunlara uygulanır

Ayrıca bkz.