Bagikan melalui


ImageList.ImageCollection.Add Metode

Definisi

Menambahkan objek yang ditentukan ke ImageList.

Overload

Nama Deskripsi
Add(Icon)

Menambahkan ikon yang ditentukan ke ImageList.

Add(Image)

Menambahkan gambar yang ditentukan ke ImageList.

Add(Image, Color)

Menambahkan gambar yang ditentukan ke ImageList, menggunakan warna yang ditentukan untuk menghasilkan masker.

Add(String, Icon)

Menambahkan ikon dengan kunci yang ditentukan ke akhir koleksi.

Add(String, Image)

Menambahkan gambar dengan kunci yang ditentukan ke akhir koleksi.

Add(Icon)

Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs

Menambahkan ikon yang ditentukan ke ImageList.

public:
 void Add(System::Drawing::Icon ^ value);
public void Add(System.Drawing.Icon value);
member this.Add : System.Drawing.Icon -> unit
Public Sub Add (value As Icon)

Parameter

value
Icon

Untuk Icon ditambahkan ke daftar.

Pengecualian

value adalah null

-atau-

nilai bukan .Icon

Contoh

Contoh kode berikut menunjukkan pembuatan ImageList, menambahkan gambar ke Images properti, mengatur ImageSize properti, dan menggunakan Draw metode . Untuk menjalankan contoh ini, letakkan dalam formulir yang berisi tombol bernama Button1. Contoh mengasumsikan keberadaan FeatherTexture.bmp dan Fishing.bmp Hilang di c:\Windows\. Ubah contoh yang sesuai jika bitmap tidak ada pada sistem Anda atau ada di lokasi lain.

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

Keterangan

dikonversi Icon ke Bitmap sebelum ditambahkan ke daftar.

Berlaku untuk

Add(Image)

Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs

Menambahkan gambar yang ditentukan ke ImageList.

public:
 void Add(System::Drawing::Image ^ value);
public void Add(System.Drawing.Image value);
member this.Add : System.Drawing.Image -> unit
Public Sub Add (value As Image)

Parameter

value
Image

Gambar Bitmap yang akan ditambahkan ke daftar.

Pengecualian

Gambar yang ditambahkan adalah null.

Gambar yang ditambahkan bukan .Bitmap

Berlaku untuk

Add(Image, Color)

Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs

Menambahkan gambar yang ditentukan ke ImageList, menggunakan warna yang ditentukan untuk menghasilkan masker.

public:
 int Add(System::Drawing::Image ^ value, System::Drawing::Color transparentColor);
public int Add(System.Drawing.Image value, System.Drawing.Color transparentColor);
member this.Add : System.Drawing.Image * System.Drawing.Color -> int
Public Function Add (value As Image, transparentColor As Color) As Integer

Parameter

value
Image

Gambar Bitmap yang akan ditambahkan ke daftar.

transparentColor
Color

untuk Color menutupi gambar ini.

Mengembalikan

Indeks gambar yang baru ditambahkan, atau -1 jika gambar tidak dapat ditambahkan.

Pengecualian

Gambar yang ditambahkan adalah null.

Gambar yang ditambahkan bukan .Bitmap

Berlaku untuk

Add(String, Icon)

Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs

Menambahkan ikon dengan kunci yang ditentukan ke akhir koleksi.

public:
 void Add(System::String ^ key, System::Drawing::Icon ^ icon);
public void Add(string key, System.Drawing.Icon icon);
member this.Add : string * System.Drawing.Icon -> unit
Public Sub Add (key As String, icon As Icon)

Parameter

key
String

Nama ikon.

icon
Icon

untuk Icon ditambahkan ke koleksi.

Pengecualian

icon adalah null.

Keterangan

Nama gambar sesuai dengan kuncinya di ImageList.ImageCollection. Kunci gambar tidak peka huruf besar/kecil.

Berlaku untuk

Add(String, Image)

Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs
Sumber:
ImageList.ImageCollection.cs

Menambahkan gambar dengan kunci yang ditentukan ke akhir koleksi.

public:
 void Add(System::String ^ key, System::Drawing::Image ^ image);
public void Add(string key, System.Drawing.Image image);
member this.Add : string * System.Drawing.Image -> unit
Public Sub Add (key As String, image As Image)

Parameter

key
String

Nama gambar.

image
Image

untuk Image ditambahkan ke koleksi.

Pengecualian

image adalah null.

Keterangan

Nama gambar sesuai dengan kuncinya di ImageList.ImageCollection. Kunci gambar tidak peka huruf besar/kecil.

Berlaku untuk