Label.Image Property

Definition

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

public System.Drawing.Image Image { get; set; }
public System.Drawing.Image? Image { get; set; }

Property Value

An Image displayed on the Label. The default is null.

Examples

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...
}

Remarks

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.

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