Display image using PictureBox and ImageList in C# ( Windows Form )

Published on Thursday, January 6, 2011

The regular way to display image in a Windows Form is using PictureBox.

Here is a sample :

First put a PictureBox control and ImageList control in Form1:


 private void Form1_Load(object sender, EventArgs e)
 {
     Rectangle cloneRect = new Rectangle(Properties.Resources.tray_icons.Width / 5 * 3 + 1, 0, Properties.Resources.tray_icons.Width / 5, Properties.Resources.tray_icons.Height);

     System.Drawing.Imaging.PixelFormat format = Properties.Resources.tray_icons.PixelFormat;
     Bitmap cloneBitmap = Properties.Resources.tray_icons.Clone(cloneRect, format);

     this.imageList1.Images.Add(cloneBitmap);
     this.imageList1.ImageSize = new Size(32, 32);

     this.pictureBox1.Image = this.imageList1.Images[0];

 }