Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ImageList.Draw Method

Draws the indicated image.

Overload List

Draws the image indicated by the specified index on the specified Graphics at the given location.

[Visual Basic] Overloads Public Sub Draw(Graphics, Point, Integer)
[C#] public void Draw(Graphics, Point, int);
[C++] public: void Draw(Graphics*, Point, int);
[JScript] public function Draw(Graphics, Point, int);

Draws the image indicated by the given index on the specified Graphics at the specified location.

[Visual Basic] Overloads Public Sub Draw(Graphics, Integer, Integer, Integer)
[C#] public void Draw(Graphics, int, int, int);
[C++] public: void Draw(Graphics*, int, int, int);
[JScript] public function Draw(Graphics, int, int, int);

Draw the image indicated by the given index on the specified Graphics object using the specified location and size.

[Visual Basic] Overloads Public Sub Draw(Graphics, Integer, Integer, Integer, Integer, Integer)
[C#] public void Draw(Graphics, int, int, int, int, int);
[C++] public: void Draw(Graphics*, int, int, int, int, int);
[JScript] public function Draw(Graphics, int, int, int, int, int);

Example

[Visual Basic, C#] The following example demonstrates constructing an ImageList setting the ImageSize property and the use of the Draw method. To run this sample place it in a form containing a button named Button1. The sample assumes the existence of FeatherTexture.bmp and Gone Fishing.bmp at c:\Windows\. Change the sample accordingly if the bitmaps do not exist on your system, or exist at another location. Ensure the button's click event is connected to the event handling method in this example.

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of Draw. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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


[C#] 
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);
    }
}

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

ImageList Class | ImageList Members | System.Windows.Forms Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft