ImageList ImageList ImageList ImageList Class


Fornisce i metodi per la gestione di un insieme di oggetti Image.Provides methods to manage a collection of Image objects. Questa classe non può essere ereditata.This class cannot be inherited.

public ref class ImageList sealed : System::ComponentModel::Component
public sealed class ImageList : System.ComponentModel.Component
type ImageList = class
    inherit Component
Public NotInheritable Class ImageList
Inherits Component


Nell'esempio di codice riportato di seguito viene illustrato come selezionare, rimuovere e visualizzare immagini.The following code example shows how to select, remove, and display images.

namespace myImageRotator
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
    using namespace System;
    using namespace System::Drawing;
    using namespace System::ComponentModel;
    using namespace System::Windows::Forms;

    public ref class Form1 : public System::Windows::Forms::Form
        System::ComponentModel::IContainer^ components;
        System::Windows::Forms::ListBox^ listBox1;
        System::Windows::Forms::Label^ label3;
        System::Windows::Forms::Button^ button1;
        System::Windows::Forms::Button^ button2;
        System::Windows::Forms::Button^ button3;
        System::Windows::Forms::Button^ button4;
        System::Windows::Forms::PictureBox^ pictureBox1;
        System::Windows::Forms::ImageList^ imageList1;
        System::Windows::Forms::OpenFileDialog^ openFileDialog1;
        Graphics^ myGraphics;
        System::Windows::Forms::Panel^ panel1;
        System::Windows::Forms::Label^ label5;
        int currentImage;

            imageList1 = gcnew ImageList () ;
            currentImage = 0;

            // The default image size is 16 x 16, which sets up a larger
            // image size. 
            imageList1->ImageSize = System::Drawing::Size(255,255);
            imageList1->TransparentColor = Color::White;

            // Assigns the graphics object to use in the draw options.
            myGraphics = Graphics::FromHwnd(panel1->Handle);

        void InitializeComponent()
            this->components = gcnew System::ComponentModel::Container();
            this->listBox1 = gcnew System::Windows::Forms::ListBox();
            this->label3 = gcnew System::Windows::Forms::Label();
            this->button1 = gcnew System::Windows::Forms::Button();
            this->button2 = gcnew System::Windows::Forms::Button();
            this->button3 = gcnew System::Windows::Forms::Button();
            this->button4 = gcnew System::Windows::Forms::Button();
            this->pictureBox1 = gcnew System::Windows::Forms::PictureBox();
            this->imageList1 = gcnew System::Windows::Forms::ImageList(this->components);
            this->openFileDialog1 = gcnew System::Windows::Forms::OpenFileDialog();
            this->panel1 = gcnew System::Windows::Forms::Panel();
            this->label5 = gcnew System::Windows::Forms::Label();

            this->listBox1->Location = System::Drawing::Point(16, 16);
            this->listBox1->Size = System::Drawing::Size(400, 95);
            this->listBox1->TabIndex = 0;

            this->label3->Location = System::Drawing::Point(24, 168);
            this->label3->Text = "label3";

            this->button1->Location = System::Drawing::Point(96, 128);
            this->button1->Size = System::Drawing::Size(104, 23);
            this->button1->Text = "Show Next Image";
            this->button1->Click += gcnew System::EventHandler(this,&Form1::button1_Click);

            this->button2->Location = System::Drawing::Point(208, 128);
            this->button2->Size = System::Drawing::Size(104, 23);
            this->button2->Text = "Remove Image";
            this->button2->Click += gcnew System::EventHandler(this,&Form1::button2_Click);

            this->button3->Location = System::Drawing::Point(320, 128);
            this->button3->Text = "Clear List";
            this->button3->Click += gcnew System::EventHandler(this,&Form1::button3_Click);

            this->button4->Location = System::Drawing::Point(16, 128);
            this->button4->Text = "Open Image";
            this->button4->Click += gcnew System::EventHandler(this,&Form1::button4_Click);

            this->pictureBox1->Location = System::Drawing::Point(328, 232);
            this->pictureBox1->Size = System::Drawing::Size(336, 192);

            this->imageList1->ImageSize = System::Drawing::Size(16, 16);
            this->imageList1->TransparentColor = System::Drawing::Color::Transparent;

            this->panel1->Location = System::Drawing::Point(8, 240);
            this->panel1->Size = System::Drawing::Size(296, 184);

            this->label5->Location = System::Drawing::Point(168, 168);
            this->label5->Size = System::Drawing::Size(312, 40);
            this->label5->Text = "label5";

            this->ClientSize = System::Drawing::Size(672, 461);

        // Display the image.
        void button1_Click (Object^ /*sender*/, System::EventArgs^ /*e*/)
            if(imageList1->Images->Empty != true)
                if(imageList1->Images->Count-1 > currentImage)

                // Draw the image in the panel.

                // Show the image in the PictureBox.
                pictureBox1->Image = imageList1->Images[currentImage];
                label3->Text = "Current image is " + currentImage ;
                listBox1->SelectedIndex = currentImage;
                //				label5->Text = "Image is " + listBox1->Text ;
                label5->Text = String::Concat("Image is ",listBox1->Text);

        // Remove the image.
        void button2_Click (Object^ /*sender*/, System::EventArgs^ /*e*/)

        // Clear all images.
        void button3_Click (Object^ /*sender*/, System::EventArgs^ /*e*/)

        // Find an image.
        void button4_Click (Object^ /*sender*/, System::EventArgs^ /*e*/)
            openFileDialog1->Multiselect = true ;
            if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
                if (openFileDialog1->FileNames != nullptr)
                    for(int i =0 ; i < openFileDialog1->FileNames->Length ; i++ )

        void addImage(String^ imageToLoad)
            if (imageToLoad != "")

        static void Main(array<String^>^ /*args*/) 
            Application::Run(gcnew Form1());

int main(){
namespace myImageRotator
	using System;
	using System.Drawing;
	using System.ComponentModel;
	using System.Windows.Forms;
	public class Form1 : System.Windows.Forms.Form
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		protected Graphics myGraphics;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label5;
		private int currentImage = 0;
		public Form1()
			imageList1 = new ImageList () ;

			// The default image size is 16 x 16, which sets up a larger
			// image size. 
			imageList1.ImageSize = new Size(255,255);
			imageList1.TransparentColor = Color.White;

			// Assigns the graphics object to use in the draw options.
			myGraphics = Graphics.FromHwnd(panel1.Handle);
        private void InitializeComponent()
            this.components = new System.ComponentModel.Container();
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.label3 = new System.Windows.Forms.Label();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.button4 = new System.Windows.Forms.Button();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.panel1 = new System.Windows.Forms.Panel();
            this.label5 = new System.Windows.Forms.Label();

            this.listBox1.Location = new System.Drawing.Point(16, 16);
            this.listBox1.Size = new System.Drawing.Size(400, 95);
            this.listBox1.TabIndex = 0;

            this.label3.Location = new System.Drawing.Point(24, 168);
            this.label3.Text = "label3";

            this.button1.Location = new System.Drawing.Point(96, 128);
            this.button1.Size = new System.Drawing.Size(104, 23);
            this.button1.Text = "Show Next Image";
            this.button1.Click += new System.EventHandler(this.button1_Click);

            this.button2.Location = new System.Drawing.Point(208, 128);
            this.button2.Size = new System.Drawing.Size(104, 23);
            this.button2.Text = "Remove Image";
            this.button2.Click += new System.EventHandler(this.button2_Click);

            this.button3.Location = new System.Drawing.Point(320, 128);
            this.button3.Text = "Clear List";
            this.button3.Click += new System.EventHandler(this.button3_Click);

            this.button4.Location = new System.Drawing.Point(16, 128);
            this.button4.Text = "Open Image";
            this.button4.Click += new System.EventHandler(this.button4_Click);

            this.pictureBox1.Location = new System.Drawing.Point(328, 232);
            this.pictureBox1.Size = new System.Drawing.Size(336, 192);

            this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;

            this.panel1.Location = new System.Drawing.Point(8, 240);
            this.panel1.Size = new System.Drawing.Size(296, 184);

            this.label5.Location = new System.Drawing.Point(168, 168);
            this.label5.Size = new System.Drawing.Size(312, 40);
            this.label5.Text = "label5";

            this.ClientSize = new System.Drawing.Size(672, 461);

        // Display the image.
        private void button1_Click (object sender, System.EventArgs e)
			if(imageList1.Images.Empty != true)
				if(imageList1.Images.Count-1 > currentImage)
                // Draw the image in the panel.

                // Show the image in the PictureBox.
				pictureBox1.Image = imageList1.Images[currentImage];
				label3.Text = "Current image is " + currentImage ;
				listBox1.SelectedIndex = currentImage;
				label5.Text = "Image is " + listBox1.Text ;
        // Remove the image.
		private void button2_Click (object sender, System.EventArgs e)
        // Clear all images.
		private void button3_Click (object sender, System.EventArgs e)
        // Find an image.
		private void button4_Click (object sender, System.EventArgs e)
			openFileDialog1.Multiselect = true ;
			if(openFileDialog1.ShowDialog() == DialogResult.OK)
				if (openFileDialog1.FileNames != null)
					for(int i =0 ; i < openFileDialog1.FileNames.Length ; i++ )
		private void addImage(string imageToLoad)
			if (imageToLoad != "")
        public static void Main(string[] args) 
			Application.Run(new Form1());
Imports System
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms

Public Class Form1
    Inherits System.Windows.Forms.Form
    Private listBox1 As System.Windows.Forms.ListBox
    Private label3 As System.Windows.Forms.Label
    Private WithEvents button1 As System.Windows.Forms.Button
    Private WithEvents button2 As System.Windows.Forms.Button
    Private WithEvents button3 As System.Windows.Forms.Button
    Private WithEvents button4 As System.Windows.Forms.Button
    Private pictureBox1 As System.Windows.Forms.PictureBox
    Private imageList1 As System.Windows.Forms.ImageList
    Private openFileDialog1 As System.Windows.Forms.OpenFileDialog
    Protected myGraphics As Graphics
    Private panel1 As System.Windows.Forms.Panel
    Private label5 As System.Windows.Forms.Label
    Private currentImage As Integer = 0

    Public Sub New()
        imageList1 = New ImageList()

        ' The default image size is 16 x 16, which sets up a larger
        ' image size. 
        imageList1.ImageSize = New Size(255, 255)
        imageList1.TransparentColor = Color.White

        ' Assigns the graphics object to use in the draw options.
        myGraphics = Graphics.FromHwnd(panel1.Handle)

    End Sub 'New

    Private Sub InitializeComponent()

        Me.listBox1 = New System.Windows.Forms.ListBox()
        Me.label3 = New System.Windows.Forms.Label()
        Me.button1 = New System.Windows.Forms.Button()
        Me.button2 = New System.Windows.Forms.Button()
        Me.button3 = New System.Windows.Forms.Button()
        Me.button4 = New System.Windows.Forms.Button()
        Me.pictureBox1 = New System.Windows.Forms.PictureBox()
        Me.openFileDialog1 = New System.Windows.Forms.OpenFileDialog()
        Me.panel1 = New System.Windows.Forms.Panel()
        Me.label5 = New System.Windows.Forms.Label()

        Me.listBox1.Location = New System.Drawing.Point(16, 16)
        Me.listBox1.Size = New System.Drawing.Size(400, 95)
        Me.listBox1.TabIndex = 0

        Me.label3.Location = New System.Drawing.Point(24, 168)
        Me.label3.Text = "label3"

        Me.button1.Location = New System.Drawing.Point(96, 128)
        Me.button1.Size = New System.Drawing.Size(104, 23)
        Me.button1.Text = "Show Next Image"

        Me.button2.Location = New System.Drawing.Point(208, 128)
        Me.button2.Size = New System.Drawing.Size(104, 23)
        Me.button2.Text = "Remove Image"

        Me.button3.Location = New System.Drawing.Point(320, 128)
        Me.button3.Text = "Clear List"

        Me.button4.Location = New System.Drawing.Point(16, 128)
        Me.button4.Text = "Open Image"

        Me.pictureBox1.Location = New System.Drawing.Point(328, 232)
        Me.pictureBox1.Size = New System.Drawing.Size(336, 192)

        Me.imageList1.ImageSize = New System.Drawing.Size(16, 16)
        Me.imageList1.TransparentColor = System.Drawing.Color.Transparent

        Me.panel1.Location = New System.Drawing.Point(8, 240)
        Me.panel1.Size = New System.Drawing.Size(296, 184)

        Me.label5.Location = New System.Drawing.Point(168, 168)
        Me.label5.Size = New System.Drawing.Size(312, 40)
        Me.label5.Text = "label5"

        Me.ClientSize = New System.Drawing.Size(672, 461)
    End Sub

    ' Display the image.
    Private Sub button1_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles button1.Click

        If imageList1.Images.Empty <> True Then
            If imageList1.Images.Count - 1 > currentImage Then
                currentImage += 1
                currentImage = 0
            End If

            ' Draw the image in the panel.
            imageList1.Draw(myGraphics, 10, 10, currentImage)

            ' Show the image in the PictureBox.
            pictureBox1.Image = imageList1.Images(currentImage)
            label3.Text = "Current image is " + currentImage.ToString
            listBox1.SelectedIndex = currentImage
            label5.Text = "Image is " + listBox1.Text
        End If
    End Sub

    ' Remove the image.
    Private Sub button2_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles button2.Click

    End Sub

    ' Clear all images.
    Private Sub button3_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles button3.Click
    End Sub

    ' Find an image.
    Private Sub button4_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles button4.Click

        openFileDialog1.Multiselect = True
        If openFileDialog1.ShowDialog() = DialogResult.OK Then
            If (openFileDialog1.FileNames IsNot Nothing) Then
                Dim i As Integer
                For i = 0 To openFileDialog1.FileNames.Length - 1
                Next i
            End If
        End If
    End Sub

    Private Sub addImage(ByVal imageToLoad As String)
        If imageToLoad <> "" Then
        End If
    End Sub

    <StaThread()> _
    Public Shared Sub Main(ByVal args() As String)
        Application.Run(New Form1())
    End Sub
End Class


ImageListviene in genere usato da altri controlli, ad esempio ListView, TreeViewo ToolBar.ImageList is typically used by other controls, such as the ListView, TreeView, or ToolBar. È possibile aggiungere bitmap o icone a ImageListe gli altri controlli sono in grado di utilizzare le immagini come richiesto.You can add bitmaps or icons to the ImageList, and the other controls are able to use the images as they require.

ImageListUsa un handle per gestire l'elenco di immagini.ImageList uses a handle to manage the list of images. L' Handle oggetto non viene creato fino a quando determinate operazioni, ad Handle esempio il Drawrecupero o la chiamata di, vengono eseguite nell'elenco immagini.The Handle is not created until certain operations, such as getting the Handle or calling Draw, are performed on the image list. L'esecuzione di altre operazioni, ad esempio ColorDepth l' ImageSize impostazione di o Handle , comporterà la ricreazione dell'oggetto.Performing other operations, such as setting the ColorDepth or ImageSize will cause the Handle to be recreated. Pertanto, è necessario eseguire queste operazioni prima di aggiungere immagini a ImageList.Therefore, you should perform these operations before you add images to the ImageList. Inoltre, quando si utilizzano i moduli che verranno localizzati, è necessario aggiungere ImageList sempre le immagini e quando la proprietà Language di un form è impostata su default.In addition, when you work with forms that will be localized, you should always add an ImageList and images when the Language property of a form is set to Default. Se si modifica la lingua del modulo prima di aggiungere immagini, i file di risorse dell'applicazione saranno danneggiati.Changing the form's language before you add images will corrupt the application resource files.


ImageList() ImageList() ImageList() ImageList()

Inizializza una nuova istanza della classe ImageList con i valori predefiniti per ColorDepth, ImageSize e TransparentColor.Initializes a new instance of the ImageList class with default values for ColorDepth, ImageSize, and TransparentColor.

ImageList(IContainer) ImageList(IContainer) ImageList(IContainer) ImageList(IContainer)

Inizializza una nuova istanza della classe ImageList associandola a un contenitore.Initializes a new instance of the ImageList class, associating it with a container.


CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

Ottiene un valore che indica se il componente può generare un evento.Gets a value indicating whether the component can raise an event.

(Inherited from Component)
ColorDepth ColorDepth ColorDepth ColorDepth

Ottiene la profondità di colore dell'elenco immagini.Gets the color depth of the image list.

Container Container Container Container

Ottiene il IContainer che contiene il Component.Gets the IContainer that contains the Component.

(Inherited from Component)
DesignMode DesignMode DesignMode DesignMode

Ottiene un valore che indica se il Component si trova in modalità progettazione.Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

Ottiene l'elenco dei gestori eventi allegati a questo Component.Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
Handle Handle Handle Handle

Ottiene l'handle dell'oggetto elenco immagini.Gets the handle of the image list object.

HandleCreated HandleCreated HandleCreated HandleCreated

Ottiene un valore che indica se l'handle Win32 sottostante è stato creato.Gets a value indicating whether the underlying Win32 handle has been created.

Images Images Images Images

Ottiene l'oggetto ImageList.ImageCollection di questo elenco immagini.Gets the ImageList.ImageCollection for this image list.

ImageSize ImageSize ImageSize ImageSize

Ottiene o imposta la dimensione delle immagini nell'elenco immagini.Gets or sets the size of the images in the image list.

ImageStream ImageStream ImageStream ImageStream

Ottiene la classe ImageListStreamer associata a questo elenco immagini.Gets the ImageListStreamer associated with this image list.

Site Site Site Site

Ottiene o imposta l'oggetto ISite di Component.Gets or sets the ISite of the Component.

(Inherited from Component)
Tag Tag Tag Tag

Ottiene o imposta un oggetto che contiene ulteriori dati relativi a ImageList.Gets or sets an object that contains additional data about the ImageList.

TransparentColor TransparentColor TransparentColor TransparentColor

Ottiene o imposta il colore da considerare trasparente.Gets or sets the color to treat as transparent.


CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Consente di creare un oggetto che contiene tutte le informazioni rilevanti necessarie per la generazione del proxy utilizzato per effettuare la comunicazione con un oggetto remoto.Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

Rilascia tutte le risorse usate da Component.Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Rilascia le risorse non gestite usate da Component e, facoltativamente, le risorse gestite.Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Draw(Graphics, Int32, Int32, Int32) Draw(Graphics, Int32, Int32, Int32) Draw(Graphics, Int32, Int32, Int32) Draw(Graphics, Int32, Int32, Int32)

Disegna l'immagine indicata dall'indice dato sul Graphics specificato nella posizione specificata.Draws the image indicated by the given index on the specified Graphics at the specified location.

Draw(Graphics, Int32, Int32, Int32, Int32, Int32) Draw(Graphics, Int32, Int32, Int32, Int32, Int32) Draw(Graphics, Int32, Int32, Int32, Int32, Int32) Draw(Graphics, Int32, Int32, Int32, Int32, Int32)

Disegna l'immagine indicata dall'indice dato sull'oggetto Graphics specificato utilizzando la posizione e le dimensioni specificate.Draws the image indicated by the given index on the specified Graphics using the specified location and size.

Draw(Graphics, Point, Int32) Draw(Graphics, Point, Int32) Draw(Graphics, Point, Int32) Draw(Graphics, Point, Int32)

Disegna l'immagine indicata dall'indice specificato sull'oggetto Graphics e nella posizione specificati.Draws the image indicated by the specified index on the specified Graphics at the given location.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Consente di recuperare l'oggetto servizio di durata corrente per controllare i criteri di durata per l'istanza.Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

Consente di restituire un oggetto che rappresenta un servizio fornito da Component o dal relativo Container.Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Ottiene un oggetto servizio di durata per controllare i criteri di durata per questa istanza.Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Crea una copia dei riferimenti dell'oggetto MarshalByRefObject corrente.Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString() ToString() ToString() ToString()

Restituisce una stringa che rappresenta l'oggetto ImageList corrente.Returns a string that represents the current ImageList.


Disposed Disposed Disposed Disposed

Si verifica quando il componente viene eliminato da una chiamata al metodo Dispose().Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
RecreateHandle RecreateHandle RecreateHandle RecreateHandle

Si verifica quando viene ricreata la proprietà Handle.Occurs when the Handle is recreated.

Si applica a

Vedi anche