ImageList Konstruktoren

Definition

Initialisiert eine neue Instanz der ImageList-Klasse.

Überlädt

ImageList()

Initialisiert eine neue Instanz der ImageList-Klasse mit Standardwerten für ColorDepth, ImageSize und TransparentColor.

ImageList(IContainer)

Initialisiert eine neue Instanz der ImageList-Klasse und ordnet diese einem Container zu.

ImageList()

Initialisiert eine neue Instanz der ImageList-Klasse mit Standardwerten für ColorDepth, ImageSize und TransparentColor.

public:
 ImageList();
public ImageList ();
Public Sub New ()

Beispiele

Das folgende Codebeispiel veranschaulicht das Erstellen eines ImageList, das Images Hinzufügen von Bildern zur -Eigenschaft, das Festlegen der ImageSize -Eigenschaft und die Verwendung der Draw -Methode. Um dieses Beispiel auszuführen, platzieren Sie es in einem Formular, das eine Schaltfläche mit dem Namen enthält Button1. Im Beispiel wird davon ausgegangen, dass und Gone Fishing.bmp unter c:\Windows\ vorhanden FeatherTexture.bmp ist. Ändern Sie das Beispiel entsprechend, wenn die Bitmaps nicht auf Ihrem System vorhanden sind oder an einer anderen Stelle vorhanden sind.

internal:
   System::Windows::Forms::ImageList^ ImageList1;

private:

   // Create an ImageList Object, populate it, and display
   // the images it contains.
   void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      
      // Construct the ImageList.
      ImageList1 = gcnew ImageList;
      
      // Set the ImageSize property to a larger size 
      // (the default is 16 x 16).
      ImageList1->ImageSize = System::Drawing::Size( 112, 112 );
      
      // Add two images to the list.
      ImageList1->Images->Add( Image::FromFile( "c:\\windows\\FeatherTexture.bmp" ) );
      ImageList1->Images->Add( Image::FromFile( "C:\\windows\\Gone Fishing.bmp" ) );
      
      // Get a Graphics object from the form's handle.
      Graphics^ theGraphics = Graphics::FromHwnd( this->Handle );
      
      // Loop through the images in the list, drawing each image.
      for ( int count = 0; count < ImageList1->Images->Count; count++ )
      {
         ImageList1->Draw( theGraphics, Point(85,85), count );
         
         // Call Application.DoEvents to force a repaint of the form.
         Application::DoEvents();
         
         // Call the Sleep method to allow the user to see the image.
         System::Threading::Thread::Sleep( 1000 );

      }
   }
internal System.Windows.Forms.ImageList ImageList1;

// Create an ImageList Object, populate it, and display
// the images it contains.
private void Button1_Click(System.Object sender, 
    System.EventArgs e)
{

    // Construct the ImageList.
    ImageList1 = new ImageList();

    // Set the ImageSize property to a larger size 
    // (the default is 16 x 16).
    ImageList1.ImageSize = new Size(112, 112);

    // Add two images to the list.
    ImageList1.Images.Add(
        Image.FromFile("c:\\windows\\FeatherTexture.bmp"));
    ImageList1.Images.Add(
        Image.FromFile("C:\\windows\\Gone Fishing.bmp"));

    // Get a Graphics object from the form's handle.
    Graphics theGraphics = Graphics.FromHwnd(this.Handle);

    // Loop through the images in the list, drawing each image.
    for(int count = 0; count < ImageList1.Images.Count; count++)
    {
        ImageList1.Draw(theGraphics, new Point(85, 85), count);

        // Call Application.DoEvents to force a repaint of the form.
        Application.DoEvents();

        // Call the Sleep method to allow the user to see the image.
        System.Threading.Thread.Sleep(1000);
    }
}
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList

' Create an ImageList Object, populate it, and display
' the images it contains.
Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    ' Construct the ImageList.
    ImageList1 = New ImageList

    ' Set the ImageSize property to a larger size 
    ' (the default is 16 x 16).
    ImageList1.ImageSize = New Size(112, 112)

    ' Add two images to the list.
    ImageList1.Images.Add(Image.FromFile _
        ("c:\windows\FeatherTexture.bmp"))
    ImageList1.Images.Add _
        (Image.FromFile("C:\windows\Gone Fishing.bmp"))

    Dim count As System.Int32

    ' Get a Graphics object from the form's handle.
    Dim theGraphics As Graphics = Graphics.FromHwnd(Me.Handle)

    ' Loop through the images in the list, drawing each image.
    For count = 0 To ImageList1.Images.Count - 1
        ImageList1.Draw(theGraphics, New Point(85, 85), count)

        ' Call Application.DoEvents to force a repaint of the form.
        Application.DoEvents()

        ' Call the Sleep method to allow the user to see the image.
        System.Threading.Thread.Sleep(1000)
    Next
End Sub

Hinweise

In der folgenden Tabelle sind die anfänglichen Eigenschaftswerte für eine instance von ImageListaufgeführt.

Element BESCHREIBUNG
ColorDepth In .NET Framework und .NET (Core)-Versionen über .NET 7 ist Depth8Bitder Standardwert . In .NET 8 und höheren Versionen ist Depth32Bitder Standardwert .
ImageSize Der Standardwert ist ein Size Objekt mit einer Höhe und Breite von 16 x 16.
TransparentColor Der Standardwert ist Transparent.

Gilt für:

ImageList(IContainer)

Initialisiert eine neue Instanz der ImageList-Klasse und ordnet diese einem Container zu.

public:
 ImageList(System::ComponentModel::IContainer ^ container);
public ImageList (System.ComponentModel.IContainer container);
new System.Windows.Forms.ImageList : System.ComponentModel.IContainer -> System.Windows.Forms.ImageList
Public Sub New (container As IContainer)

Parameter

container
IContainer

Ein Objekt, das den IContainer implementiert und dieser Instanz von ImageList zugeordnet werden soll.

Hinweise

Mit dem ImageList Konstruktor können Sie ein ImageList beliebiges Container Objekt zuordnen. Indem Sie die ImageList wie folgt zuordnen, übergeben Sie die Kontrolle über die Lebensdauer von ImageList an den Container. Dies kann nützlich sein, wenn Sie eine Reihe von Komponenten in Ihrer Anwendung verwenden und alle gleichzeitig entsorgen möchten. Wenn Sie z. B. ein ToolTip, ein ImageListund ein Timer mit einem Containerzuordnen, erzwingt das Aufrufen Dispose des Containers auch die Beseitigung aller dieser Komponenten.

Gilt für: