Label.Image Propriété

Définition

Obtient ou définit l'image affichée sur un Label.

public:
 property System::Drawing::Image ^ Image { System::Drawing::Image ^ get(); void set(System::Drawing::Image ^ value); };
public System.Drawing.Image Image { get; set; }
public System.Drawing.Image? Image { get; set; }
member this.Image : System.Drawing.Image with get, set
Public Property Image As Image

Valeur de propriété

Image

Une Image affichée sur Label. La valeur par défaut est null.

Exemples

L’exemple de code suivant montre comment créer un Label élément, puis afficher un Image derrière le Label. Tout d’abord, l’exemple crée un Label fichier disque, puis crée un Image fichier de disque. Ensuite, la Size propriété est initialisée pour contenir le Image. Enfin, la Image propriété est initialisée sur le 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...
   }
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...
}
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

Remarques

La Image propriété ne peut pas être utilisée en même temps que les propriétés et ImageIndex les ImageList propriétés. Lorsque la Image propriété est utilisée pour afficher une image, les ImageList propriétés sont ImageIndex automatiquement définies sur leurs paramètres par défaut.

S’applique à

Voir aussi