ImageList Constructeurs

Définition

Initialise une nouvelle instance de la classe ImageList.

Surcharges

ImageList()

Initialise une nouvelle instance de la classe ImageList avec des valeurs par défaut pour ColorDepth, ImageSize et TransparentColor.

ImageList(IContainer)

Initialise une nouvelle instance de la classe ImageList, en l'associant à un conteneur.

ImageList()

Initialise une nouvelle instance de la classe ImageList avec des valeurs par défaut pour ColorDepth, ImageSize et TransparentColor.

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

Exemples

L’exemple de code suivant illustre la construction d’un , l’ajout d’images ImageListà la Images propriété, la définition de la ImageSize propriété et l’utilisation de la Draw méthode . Pour exécuter cet exemple, placez-le dans un formulaire contenant un bouton nommé Button1. L’exemple suppose l’existence de FeatherTexture.bmp et Gone Fishing.bmp à l’emplacement c:\Windows\. Modifiez l’exemple en conséquence si les bitmaps n’existent pas sur votre système ou si elles existent à un autre emplacement.

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

Remarques

Le tableau suivant montre les valeurs de propriété initiales d’un instance de ImageList.

Élément Description
ColorDepth Dans les versions .NET Framework et .NET (Core) à .NET 7, la valeur par défaut est Depth8Bit. Dans .NET 8 et versions ultérieures, la valeur par défaut est Depth32Bit.
ImageSize La valeur par défaut est un Size objet avec une hauteur et une largeur de 16 par 16.
TransparentColor La valeur par défaut est Transparent.

S’applique à

ImageList(IContainer)

Initialise une nouvelle instance de la classe ImageList, en l'associant à un conteneur.

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)

Paramètres

container
IContainer

Un objet implémentant IContainer à associer à cette instance de ImageList.

Remarques

Le ImageList constructeur vous permet d’associer un à n’importe ImageList quel Container objet. En associant le ImageList comme ceci, vous passez le contrôle de la durée de vie du ImageList à .Container Cela peut être utile si vous utilisez un certain nombre de composants dans votre application et que vous souhaitez les supprimer simultanément. Par exemple, si vous associez un ToolTip, un ImageListet un à un ContainerTimer , l’appel Dispose sur le conteneur force également la suppression de tous ces composants.

S’applique à