Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
PictureBox Class
 Image Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
PictureBox..::.Image Property

Gets or sets the image that is displayed by PictureBox.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
<BindableAttribute(True)> _
Public Property Image As Image
Visual Basic (Usage)
Dim instance As PictureBox
Dim value As Image

value = instance.Image

instance.Image = value
C#
[BindableAttribute(true)]
public Image Image { get; set; }
Visual C++
[BindableAttribute(true)]
public:
property Image^ Image {
    Image^ get ();
    void set (Image^ value);
}
JScript
public function get Image () : Image
public function set Image (value : Image)

Property Value

Type: System.Drawing..::.Image
The Image to display.

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

NoteNote:

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.

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.

Visual Basic
Private pictureBox1 As New PictureBox()

Public Sub CreateBitmapAtRuntime() 
    pictureBox1.Size = New Size(210, 110)
    Me.Controls.Add(pictureBox1)


    Dim flag As New Bitmap(200, 100)
    Dim flagGraphics As Graphics = Graphics.FromImage(flag)
    Dim red As Integer = 0
    Dim white As Integer = 11
    While white <= 100
        flagGraphics.FillRectangle(Brushes.Red, 0, red, 200, 10)
        flagGraphics.FillRectangle(Brushes.White, 0, white, 200, 10)
        red += 20
        white += 20
    End While
    pictureBox1.Image = flag

End Sub 

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;

}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker