PictureBox.Image Property

Definition

Gets or sets the image that is displayed by PictureBox.

C#
public System.Drawing.Image Image { get; set; }
C#
[System.ComponentModel.Bindable(true)]
public System.Drawing.Image Image { get; set; }
C#
[System.ComponentModel.Bindable(true)]
public System.Drawing.Image? Image { get; set; }

Property Value

The Image to display.

Attributes

Examples

The following code example demonstrates how to create a bitmap at runtime and display it in a PictureBox by setting the Image property. To run this example, paste it into a Windows Form and call CreateBitmapAtRuntime from the form's constructor.

C#
PictureBox pictureBox1 = new PictureBox();
public void CreateBitmapAtRuntime()
{
    pictureBox1.Size = new Size(210, 110);
    this.Controls.Add(pictureBox1);

    Bitmap flag = new Bitmap(200, 100);
    Graphics flagGraphics = Graphics.FromImage(flag);
    int red = 0;
    int white = 11;
    while (white <= 100) {
        flagGraphics.FillRectangle(Brushes.Red, 0, red, 200,10);
        flagGraphics.FillRectangle(Brushes.White, 0, white, 200, 10);
        red += 20;
        white += 20;
    }
    pictureBox1.Image = flag;
}

Remarks

The Image property is set to the Image to display. You can do this either at design time or at run time.

Note

If you want to use the same image in multiple PictureBox controls, create a clone of the image for each PictureBox. Accessing the same image from multiple controls causes an exception to occur.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also