共用方式為


PictureBox.Image 屬性

定義

取得或設定 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; }
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

屬性值

Image

要顯示的 Image

屬性

範例

下列程式碼範例示範如何在執行時間建立點陣圖,並藉由設定 Image 屬性在 中 PictureBox 顯示。 若要執行此範例,請將它貼到 Windows Form,並從表單的建構函式呼叫 CreateBitmapAtRuntime

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

備註

Image 屬性設定為要顯示的 Image。 您可以在設計階段或執行時間執行此動作。

注意

如果您想要在多個 PictureBox 控制項中使用相同的映射,請為每個 PictureBox 建立映射的複製品。 從多個控制項存取相同的映射會導致發生例外狀況。

適用於

另請參閱