PictureBox.Image 屬性


取得或設定 PictureBox 顯示的影像。Gets or sets the image that is displayed by PictureBox.

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


要顯示的 ImageThe Image to display.



下列程式碼範例示範如何在執行時間建立點陣圖,並藉由設定 Image 屬性,將它顯示在 PictureBox 中。The following code example demonstrates how to create a bitmap at runtime and display it in a PictureBox by setting the Image property. 若要執行此範例,請將它貼入 Windows Form,並從表單的「函式」呼叫 CreateBitmapAtRuntimeTo run this example, paste it into a Windows Form and call CreateBitmapAtRuntime from the form's constructor.

PictureBox pictureBox1 = new PictureBox();
public void CreateBitmapAtRuntime()
    pictureBox1.Size = new Size(210, 110);

    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)
    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 


Image 屬性設定為要顯示的 ImageThe Image property is set to the Image to display. 您可以在設計階段或執行時間執行此動作。You can do this either at design time or at run time.


如果您想要在多個 PictureBox 控制項中使用相同的影像,請為每個 PictureBox建立映射的複本。If you want to use the same image in multiple PictureBox controls, create a clone of the image for each PictureBox. 從多個控制項存取相同的影像會導致發生例外狀況。Accessing the same image from multiple controls causes an exception to occur.