Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

Draw Array of images using Graphics class in –

Author: Shehzad Hemani
Download Source Code :

In this simple article you will learn that how to draw array of images using Graphics class in –

 To draw the array of images on form first of all make an array of class bitmap. After that we will draw an image under form paint event using graphics class.


private Bitmap[] myImages = new Bitmap[3];


Dim myImages() As Bitmap

Draw Image:

To draw the image we have a function of graphics class named drawimage (). This function takes 5 parameters. First is the object of image class. Then the x,y coordinates on the form where the image will draw. Then the height and width of the image. This function returns nothing. This function has 29 overloaded methods. You will call this function under the loop and will pass your image one by one in this function with different x,y coordinates of form. Array of images will be drawn on the form.

To demonstrate make a window application.

Now write the following code on Form Paint Event:


private void Paint_Event(object sender, PaintEventArgs e)




                Graphics g = e.Graphics;

                int yOffset = 10;

                int x = 10;

                int height = 90;

                int width = 90;

                foreach (Bitmap b in myImages)


                    g.DrawImage(b, x, yOffset, height, width);

                    yOffset += 100;



            catch (Exception ex) { }



Private Sub Paint_Event(ByVal sender As ObjectByVal As PaintEventArgs)
As Graphics e.Graphics
Dim yOffset As Integer = 10
Dim As Integer = 10
Dim height As Integer = 90
Dim width As Integer = 90
For Each As Bitmap In myImages
                g.DrawImage(b, x, yOffset, height, width)
(yOffset + 100)
ex As Exception
        End Try
    End Sub

This is simple code to draw the array of images on the form.

Now write the following code on FORM LOAD event:


private void Form1_Load(object sender, EventArgs e)


            this.Text = "Devasp Application";

            myImages[0] = new Bitmap("Jellyfish.jpg");

            myImages[1] = new Bitmap("Koala.jpg");

            myImages[2] = new Bitmap("Penguins.bmp");



Private Sub Form1_Load(ByVal sender As ObjectByVal As EventArgs)
Me.Text "Devasp Application"
myImages(0= New Bitmap("Jellyfish.jpg")
1= New Bitmap("Koala.jpg")
2= New Bitmap("Penguins.bmp")
End Sub

This simple article tells that how to draw array of images using Graphics class in –

Add Article Comment:
Name :
Email Address :
Comments :
<< Get image size using binary reader in –

Disclaimer - Privacy
© 2002-2017