ButtonBase.ImageIndex 속성

정의

단추 컨트롤에 표시된 이미지의 이미지 목록 인덱스 값을 가져오거나 설정합니다.

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

속성 값

Int32

0부터 시작하는 인덱스이며, ImageList에서 이미지의 위치를 나타냅니다. 기본값은 -1입니다.

특성

예외

value이 -1보다 작습니다.

예제

다음 코드 예제에서는 파생 클래스 Button 를 사용 하 고 및 ImageIndex 속성을 설정 ImageList 합니다. 이 코드를 사용하려면 ImageList 만든 코드가 하나 Image 이상 할당되어 있어야 합니다. 또한 이 코드를 사용하려면 디렉터리에 저장된 C:\Graphics 비트 MyBitMap.bmp 맵 이미지가 있어야 합니다.

private:
   void AddMyImage()
   {
      // Assign an image to the imageList.
      imageList1->Images->Add( Image::FromFile( "C:\\Graphics\\MyBitmap.bmp" ) );
      // Assign the imageList to the button control.
      button1->ImageList = imageList1;
      // Select the image from the ImageList (using the ImageIndex property).
      button1->ImageIndex = 0;
   }
private void AddMyImage()
 {
    // Assign an image to the ImageList.
    ImageList1.Images.Add(Image.FromFile("C:\\Graphics\\MyBitmap.bmp"));
    // Assign the ImageList to the button control.   
    button1.ImageList = ImageList1;
    // Select the image from the ImageList (using the ImageIndex property).    
    button1.ImageIndex = 0;
 }
Private Sub AddMyImage()
    ' Assign an image to the ImageList.
    ImageList1.Images.Add(Image.FromFile("C:\Graphics\MyBitmap.bmp"))
    ' Assign the ImageList to the button control.   
    button1.ImageList = ImageList1
    ' Select the image from the ImageList (using the ImageIndex property).    
    button1.ImageIndex = 0
End Sub

설명

또는 ImageList 속성이 ImageIndex 설정 Image 되면 속성이 기본값null으로 설정됩니다.

ImageKeyImageIndex 은 상호 배타적입니다. 즉, 한 값이 설정된 경우 다른 값은 잘못된 값으로 설정되고 무시됩니다. 속성을 설정 ImageKey 하면 속성이 ImageIndex 자동으로 -1로 설정됩니다. 또는 속성을 ImageKey 설정하는 ImageIndex 경우 자동으로 빈 문자열("")로 설정됩니다.

속성 값이 ImageList 변경 null되면 속성은 ImageIndex 기본값 -1을 반환합니다. 그러나 할당된 ImageIndex 값은 내부적으로 유지되며 다른 ImageList 개체가 속성에 ImageList 할당될 때 사용됩니다. 속성에 ImageList 할당된 새 ImageList 속성 ImageList.ImageCollection.Count 값이 속성에 할당된 ImageIndex 값보다 작거나 같은 경우(컬렉션이 0부터 시작하는 인덱 ImageIndex 스인 경우) 속성 값이 속성 값보다 Count 작은 값으로 조정됩니다. 예를 들어 세 개의 이미지가 있고 ImageIndex 속성이 ImageList 2로 설정된 단추 컨트롤을 고려해 보세요. 두 개의 이미지만 있는 새 ImageList 이미지가 단추에 할당되면 값이 ImageIndex 1로 변경됩니다.

적용 대상

추가 정보