Compartilhar via


ImageList Construtores

Definição

Inicializa uma nova instância da classe ImageList.

Sobrecargas

Nome Description
ImageList()

Inicializa uma nova instância da ImageList classe com valores padrão para ColorDepth, ImageSizee TransparentColor.

ImageList(IContainer)

Inicializa uma nova instância da classe, associando-a a ImageList um contêiner.

ImageList()

Origem:
ImageList.cs
Origem:
ImageList.cs
Origem:
ImageList.cs
Origem:
ImageList.cs
Origem:
ImageList.cs

Inicializa uma nova instância da ImageList classe com valores padrão para ColorDepth, ImageSizee TransparentColor.

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

Exemplos

O exemplo de código a seguir demonstra a construção de uma ImageList, adicionando imagens à Images propriedade, definindo a ImageSize propriedade e usando o Draw método. Para executar este exemplo, coloque-o em um formulário que contém um botão chamado Button1. O exemplo pressupõe a existência de FeatherTexture.bmp e Gone Fishing.bmp em c:\Windows\. Altere o exemplo de acordo se os bitmaps não existirem em seu sistema ou existirem em outro local.

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

Comentários

A tabela a seguir mostra valores de propriedade iniciais para uma instância de ImageList.

Item Descrição
ColorDepth Nas versões do .NET Framework e do .NET (Core) por meio do .NET 7, o padrão é Depth8Bit. No .NET 8 e versões posteriores, o padrão é Depth32Bit.
ImageSize O padrão é um Size objeto com uma altura e largura de 16 por 16.
TransparentColor O valor padrão é Transparent.

Aplica-se a

ImageList(IContainer)

Origem:
ImageList.cs
Origem:
ImageList.cs
Origem:
ImageList.cs
Origem:
ImageList.cs
Origem:
ImageList.cs

Inicializa uma nova instância da classe, associando-a a ImageList um contêiner.

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)

Parâmetros

container
IContainer

Um objeto que está implementando IContainer para associar a esta instância de ImageList.

Comentários

O ImageList construtor permite que você associe um ImageList a qualquer Container objeto. Ao associar assim ImageList , você entrega o controle do tempo de vida do ImageListContainer. Isso pode ser útil se você usar vários componentes em seu aplicativo e quiser descartar todos eles simultaneamente. Por exemplo, se você associar um ToolTip, um ImageListe um Timer com um Container, chamar Dispose no Contêiner também forçará o descarte de todos esses componentes.

Aplica-se a