This documentation is archived and is not being maintained.

Label.Image Property

Gets or sets the image that is displayed on a Label.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[LocalizableAttribute(true)] 
public Image Image { get; set; }
/** @property */
public Image get_Image ()

/** @property */
public void set_Image (Image value)

public function get Image () : Image

public function set Image (value : Image)

Property Value

An Image displayed on the Label. The default is a null reference (Nothing in Visual Basic).

The Image property cannot be used at the same time as the ImageList and ImageIndex properties. When the Image property is used to display an image, the ImageList and ImageIndex properties are automatically set to their default settings.

The following code example demonstrates how to create a Label and then to display an Image behind the Label. First, the example creates a Label and then creates an Image based on a disk file. Next, the Size property is initialized to contain the Image. Finally, the Image property is initialized to the Image.

public void CreateMyLabel() 
{
 
    // Create a new label and create a bitmap.

    Label label1 = new Label();
    Image image1 = Image.FromFile("c:\\MyImage.bmp");

    // Set the size of the label to accommodate the bitmap size.

    label1.Size = new Size(image1.Width, image1.Height);

    // Initialize the label control's Image property.

    label1.Image = image1;

    // ...Code to add the control to the form...

}


public void CreateMyLabel()
{
    // Create a new label and create a bitmap.
    Label label1 = new Label();
    Image image1 = Image.FromFile("c:\\MyImage.bmp");

    // Set the size of the label to accommodate the bitmap size.
    label1.set_Size(new Size(image1.get_Width(), image1.get_Height()));

    // Initialize the label control's Image property.
    label1.set_Image(image1);
} //CreateMyLabel
// ...Code to add the control to the form...

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

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

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: