ImageList 建構函式

定義

初始化 ImageList 類別的新執行個體。

多載

ImageList()

使用 ImageListColorDepthImageSize 的預設值來初始化 TransparentColor 類別的新執行個體。

ImageList(IContainer)

初始化 ImageList 類別的新執行個體,將它與容器 (Container) 相關聯。

ImageList()

使用 ImageListColorDepthImageSize 的預設值來初始化 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 的初始屬性值。

Item 描述
ColorDepth 在透過 .NET 7 的 .NET Framework 和 .NET (Core) 版本中,預設值為 Depth8Bit 。 在 .NET 8 和更新版本中,預設值為 Depth32Bit
ImageSize 預設值是 Size 高度和寬度為 16 到 16 的物件。
TransparentColor 預設值是 Transparent

適用於

ImageList(IContainer)

初始化 ImageList 類別的新執行個體,將它與容器 (Container) 相關聯。

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 可讓您與任何 Container 物件產生關聯 ImageList 。 藉由將類似這樣建立關聯 ImageList ,您可以將 的 ImageList 存留期控制權交交給 Container 。 如果您在應用程式中使用許多元件,而且想要同時處置所有元件,這非常有用。 例如,如果您將 、、 ImageList 和 與 ContainerTimer 建立關聯 ToolTip ,則容器上的 呼叫 Dispose 也會強制處置所有這些元件。

適用於