Freigeben über


ButtonBase.ImageIndex-Eigenschaft

Ruft den Indexwert des Bilds in der Bildliste ab, das auf dem Schaltflächen-Steuerelement angezeigt wird, oder legt diesen fest.

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

Syntax

'Declaration
<LocalizableAttribute(True)> _
Public Property ImageIndex As Integer
'Usage
Dim instance As ButtonBase
Dim value As Integer

value = instance.ImageIndex

instance.ImageIndex = value
[LocalizableAttribute(true)] 
public int ImageIndex { get; set; }
[LocalizableAttribute(true)] 
public:
property int ImageIndex {
    int get ();
    void set (int value);
}
/** @property */
public int get_ImageIndex ()

/** @property */
public void set_ImageIndex (int value)
public function get ImageIndex () : int

public function set ImageIndex (value : int)

Eigenschaftenwert

Ein nullbasierter Index, der die Bildposition in einer ImageList angibt. Der Standardwert ist -1.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentOutOfRangeException

Der zugewiesene Wert ist kleiner als die Untergrenze von ImageIndex.

Hinweise

Wenn die ImageIndex-Eigenschaft oder die ImageList-Eigenschaft festgelegt ist, wird die Image-Eigenschaft auf den Standardwert NULL (Nothing in Visual Basic) festgelegt.

Hinweis

Wenn der Wert der ImageList-Eigenschaft in NULL (Nothing in Visual Basic) geändert wird, gibt die ImageIndex-Eigenschaft ihren Standardwert (-1) zurück. Der zugewiesene ImageIndex-Wert wird aber intern beibehalten und verwendet, sobald der ImageList-Eigenschaft ein anderes ImageList-Objekt zugewiesen wurde. Wenn das neue ImageList-Objekt, das der ImageList-Eigenschaft zugewiesen ist, für die ImageList.ImageCollection.Count-Eigenschaft einen Wert hat, der kleiner gleich dem Wert, den die ImageIndex-Eigenschaft hat, minus 1 (um zu berücksichtigen, dass der Index der Auflistung bei 0 (null) beginnt) ist, wird der Wert der ImageIndex-Eigenschaft so angepasst, dass er um 1 kleiner ist als der Wert der Count-Eigenschaft. Stellen Sie sich beispielsweise ein Schaltflächen-Steuerelement vor, dessen ImageList drei Bilder enthält und dessen ImageIndex-Eigenschaft auf 2 festgelegt ist. Wenn der Schaltfläche eine neue ImageList zugewiesen wird, die nur zwei Bilder enthält, ändert sich der ImageIndex-Wert in 1.

Beispiel

Im folgenden Codebeispiel wird die abgeleitete Klasse Button verwendet, und die ImageList-Eigenschaft und ImageIndex-Eigenschaft werden festgelegt. Für diesen Code ist es erforderlich, dass eine ImageList erstellt und dieser mindestens ein Image zugewiesen wurde. Für diesen Code ist es außerdem erforderlich, dass im Verzeichnis C:\Graphics eine Bitmap mit dem Namen MyBitMap.bmp vorhanden ist.

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 'AddMyImage
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 void AddMyImage()
{
    // Assign an image to the ImageList.
    imageList1.get_Images().Add(Image.FromFile(
        "C:\\Graphics\\MyBitmap.bmp"));
    // Assign the ImageList to the button control.   
    button1.set_ImageList(imageList1);
    // Select the image from the ImageList (using the ImageIndex property).    
    button1.set_ImageIndex(0);
} //AddMyImage
private function AddMyImage()
 {
    // Assign an image to the ImageList.
    ImageList1 = new 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;
 }
 

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

ButtonBase-Klasse
ButtonBase-Member
System.Windows.Forms-Namespace
ImageList