Поделиться через


ImageList Конструкторы

Определение

Инициализирует новый экземпляр класса ImageList.

Перегрузки

Имя Описание
ImageList()

Инициализирует новый экземпляр ImageList класса со значениями по умолчанию для ColorDepth, ImageSizeи TransparentColor.

ImageList(IContainer)

Инициализирует новый экземпляр ImageList класса, связывая его с контейнером.

ImageList()

Исходный код:
ImageList.cs
Исходный код:
ImageList.cs
Исходный код:
ImageList.cs
Исходный код:
ImageList.cs
Исходный код:
ImageList.cs

Инициализирует новый экземпляр ImageList класса со значениями по умолчанию для ColorDepth, ImageSizeи TransparentColor.

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

Примеры

В следующем примере кода показано создание ImageList, добавление изображений в Images свойство, установка ImageSize свойства и использование Draw метода. Чтобы запустить этот пример, поместите его в форму, содержащую кнопку с именем Button1. В примере предполагается наличие и Gone Fishing.bmp в FeatherTexture.bmp C:\Windows\. Измените пример соответствующим образом, если растровые изображения не существуют в системе или существуют в другом расположении.

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

Комментарии

В следующей таблице показаны начальные значения свойств для экземпляра ImageList.

Элемент Описание
ColorDepth В версиях .NET Framework и .NET (Core) через .NET 7 используется Depth8Bitзначение по умолчанию. В .NET 8 и более поздних версиях используется Depth32Bitзначение по умолчанию.
ImageSize По умолчанию используется Size объект с высотой и шириной от 16 до 16.
TransparentColor Значение по умолчанию — Transparent.

Применяется к

ImageList(IContainer)

Исходный код:
ImageList.cs
Исходный код:
ImageList.cs
Исходный код:
ImageList.cs
Исходный код:
ImageList.cs
Исходный код:
ImageList.cs

Инициализирует новый экземпляр ImageList класса, связывая его с контейнером.

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)

Параметры

container
IContainer

Объект, реализующий IContainer связывание с этим экземпляром ImageList.

Комментарии

Конструктор ImageList позволяет связать ImageList объект с любым Container объектом. Объединяя подобноеImageList, вы передаете контроль над временем существования ImageList к .Container Это может быть полезно, если вы используете ряд компонентов в приложении и хотите удалить их одновременно. Например, если вы связываете ToolTipобъект , ImageListа также TimerContainerвызов Dispose контейнера принудительно удаляет все эти компоненты.

Применяется к