ImageList 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 ImageList 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| 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的按鈕的表單中。 範例假設 c:\Windows\ 處存在 FeatherTexture.bmp 和 Gone Fishing.bmp 。 如果點陣圖在你的系統上不存在,或在其他位置存在,請相應地修改範例。
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(核心)版本到 .NET 7 中,預設為 Depth8Bit。 在 .NET 8 及以後版本中,預設為 Depth32Bit。 |
| ImageSize | 預設的物件高度和寬度為 Size 16 x 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 構子讓你能將 a ImageList 與任何 Container 物件關聯。 透過將 這樣關聯,你將 ImageList 的生命 ImageList 週期控制權交給了 Container。 如果你在申請中使用多個組件,並希望同時處理所有零件,這會非常有用。 例如,若你將 a ToolTip、an ImageList、a Timer 與 關聯到 Container,呼叫 Dispose 容器也會強制丟棄所有這些元件。