共用方式為


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; }
[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屬性在 a PictureBox 中顯示。 要執行此範例,請將它貼到 Windows 表單中,並從表單的建構子中呼叫 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建立該影像的複製品。 從多個控制項存取同一影像會產生例外。

適用於

另請參閱