Partager via


PictureBox.Image Propriété

Définition

Obtient ou définit l’image affichée par PictureBox.

public:
 property System::Drawing::Image ^ Image { System::Drawing::Image ^ get(); void set(System::Drawing::Image ^ value); };
public System.Drawing.Image Image { get; set; }
[System.ComponentModel.Bindable(true)]
public System.Drawing.Image Image { get; set; }
[System.ComponentModel.Bindable(true)]
public System.Drawing.Image? Image { get; set; }
member this.Image : System.Drawing.Image with get, set
[<System.ComponentModel.Bindable(true)>]
member this.Image : System.Drawing.Image with get, set
Public Property Image As Image

Valeur de propriété

À Image afficher.

Attributs

Exemples

L’exemple de code suivant montre comment créer une bitmap au moment de l’exécution et l’afficher dans un PictureBox en définissant la Image propriété. Pour exécuter cet exemple, collez-le dans un Windows Form et appelez-le CreateBitmapAtRuntime à partir du constructeur du formulaire.

PictureBox pictureBox1 = new PictureBox();
public void CreateBitmapAtRuntime()
{
    pictureBox1.Size = new Size(210, 110);
    this.Controls.Add(pictureBox1);

    Bitmap flag = new Bitmap(200, 100);
    Graphics flagGraphics = Graphics.FromImage(flag);
    int red = 0;
    int white = 11;
    while (white <= 100) {
        flagGraphics.FillRectangle(Brushes.Red, 0, red, 200,10);
        flagGraphics.FillRectangle(Brushes.White, 0, white, 200, 10);
        red += 20;
        white += 20;
    }
    pictureBox1.Image = flag;
}
Private pictureBox1 As New PictureBox()

Public Sub CreateBitmapAtRuntime() 
    pictureBox1.Size = New Size(210, 110)
    Me.Controls.Add(pictureBox1)
    
    
    Dim flag As New Bitmap(200, 100)
    Dim flagGraphics As Graphics = Graphics.FromImage(flag)
    Dim red As Integer = 0
    Dim white As Integer = 11
    While white <= 100
        flagGraphics.FillRectangle(Brushes.Red, 0, red, 200, 10)
        flagGraphics.FillRectangle(Brushes.White, 0, white, 200, 10)
        red += 20
        white += 20
    End While
    pictureBox1.Image = flag

End Sub

Remarques

La Image propriété est définie sur l’affichage Image . Vous pouvez le faire au moment du design ou au moment de l’exécution.

Note

Si vous souhaitez utiliser la même image dans plusieurs PictureBox contrôles, créez un clone de l’image pour chaque PictureBox. L’accès à la même image à partir de plusieurs contrôles provoque une exception.

S’applique à

Voir aussi