ImageList.ImageCollection.Add Methode

Definition

Fügt das angegebene Objekt zur ImageList hinzu.

Überlädt

Add(Icon)

Fügt ImageList das angegebene Symbol hinzu.

Add(Image)

Fügt ImageList das angegebene Bild hinzu.

Add(Image, Color)

Fügt ImageList das angegebene Bild hinzu, wobei zum Generieren der Maske die angegebene Farbe verwendet wird.

Add(String, Icon)

Fügt ein Symbol mit dem angegebenen Schlüssel am Ende der Auflistung hinzu.

Add(String, Image)

Fügt ein Bild mit dem angegebenen Schlüssel am Ende der Auflistung hinzu.

Add(Icon)

Fügt ImageList das angegebene Symbol hinzu.

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

Ein der Liste hinzuzufügendes Icon.

Ausnahmen

value ist gleich null.

- oder -

value ist kein Icon.

Beispiele

Das folgende Codebeispiel veranschaulicht das Erstellen einer ImageList, das Images Hinzufügen von Bildern zur -Eigenschaft, das Festlegen der ImageSize -Eigenschaft und die Verwendung der Draw -Methode. Um dieses Beispiel auszuführen, platzieren Sie es in einem Formular, das eine Schaltfläche mit dem Namen Button1enthält. Im Beispiel wird davon ausgegangen, dass unter c:\Windows\ FeatherTexture.bmp und Gone Fishing.bmp vorhanden sind. Ändern Sie das Beispiel entsprechend, wenn die Bitmaps nicht auf Ihrem System oder an einem anderen Speicherort vorhanden sind.

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

Hinweise

Wird Icon in ein Bitmap konvertiert, bevor es der Liste hinzugefügt wird.

Gilt für:

Add(Image)

Fügt ImageList das angegebene Bild hinzu.

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

Eine Bitmap des Bildes, das der Liste hinzugefügt werden soll.

Ausnahmen

Das gerade hinzugefügte Bild ist null.

Das derzeit hinzugefügte Bild ist keine Bitmap.

Gilt für:

Add(Image, Color)

Fügt ImageList das angegebene Bild hinzu, wobei zum Generieren der Maske die angegebene Farbe verwendet wird.

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

Eine Bitmap des Bildes, das der Liste hinzugefügt werden soll.

transparentColor
Color

Color zum Maskieren dieses Bildes.

Gibt zurück

Der Index des neu hinzugefügten Bildes oder -1, wenn das Bild nicht hinzugefügt werden kann.

Ausnahmen

Das gerade hinzugefügte Bild ist null.

Das derzeit hinzugefügte Bild ist keine Bitmap.

Gilt für:

Add(String, Icon)

Fügt ein Symbol mit dem angegebenen Schlüssel am Ende der Auflistung hinzu.

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

Der Name des Symbols.

icon
Icon

Der der Auflistung hinzuzufügende Icon.

Ausnahmen

icon ist null.

Hinweise

Der Name eines Bilds entspricht seinem Schlüssel im ImageList.ImageCollection. Bei einem Imageschlüssel wird die Groß-/Kleinschreibung nicht beachtet.

Gilt für:

Add(String, Image)

Fügt ein Bild mit dem angegebenen Schlüssel am Ende der Auflistung hinzu.

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

Der Name des Bildes.

image
Image

Der der Auflistung hinzuzufügende Image.

Ausnahmen

image ist null.

Hinweise

Der Name eines Bilds entspricht seinem Schlüssel im ImageList.ImageCollection. Bei einem Imageschlüssel wird die Groß-/Kleinschreibung nicht beachtet.

Gilt für: