This documentation is archived and is not being maintained.

Label.Image Property

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

[Visual Basic]
Public Property Image As Image
[C#]
public Image Image {get; set;}
[C++]
public: __property Image* get_Image();
public: __property void set_Image(Image*);
[JScript]
public function get Image() : Image;
public function set Image(Image);

Property Value

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

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.

Example

[Visual Basic, C#, C++] The following 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.

[Visual Basic] 
Private Sub CreateMyLabel()

    ' Create a new label and bitmap.

    Dim Label1 As New Label()
    Dim Image1 As Image

    Image1 = Image.FromFile("c:\\MyImage.bmp")
   

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

    Label1.Size = Image1.Size        

    ' Initialize the label control's Image property.

    Label1.Image = Image1

    ' ...Code to add the control to the form...

End Sub

[C#] 
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...

}


[C++] 
public:
   void CreateMyLabel() 
   {

      // Create a new label and create a bitmap.

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

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

      label1->Size = System::Drawing::Size(image1->Width, image1->Height);

      // Initialize the label control's Image property.

      label1->Image = image1;

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

   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Label Class | Label Members | System.Windows.Forms Namespace | Image | ImageAlign | ImageList | ImageIndex

Show: