Label::Image Property
.NET Framework (current version)
Gets or sets the image that is displayed on a Label.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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 = gcnew Label; Image^ image1 = Image::FromFile( "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... }
.NET Framework
Available since 1.1
Available since 1.1
Show: