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窗体中,并从窗体的构造函数调用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控件创建映像的克隆。 从多个控件访问同一映像会导致发生异常。

适用于

另请参阅