Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将图像从Form1分配到Form2 Picturebox_C#_Windows_Winforms - Fatal编程技术网

C# 如何将图像从Form1分配到Form2 Picturebox

C# 如何将图像从Form1分配到Form2 Picturebox,c#,windows,winforms,C#,Windows,Winforms,我正在使用C#Windows应用程序创建图像编辑器,现在我无法将图像从Form1分配给Form2 picturebox 我正在尝试下面显示的代码 下面的代码是在Form1.cs页面中编写的 if(flag==0) { Form2 f2 = new Form2(glb_image_list_arr[0]); f2.Show(); } 下面的代码是在Form2.cs页面中编写的 public Form2() {

我正在使用C#Windows应用程序创建图像编辑器,现在我无法将图像从Form1分配给Form2 picturebox

我正在尝试下面显示的代码
下面的代码是在Form1.cs页面中编写的

    if(flag==0)
    {
        Form2 f2 = new Form2(glb_image_list_arr[0]);
        f2.Show();                
    }
下面的代码是在Form2.cs页面中编写的

public Form2()
{
    InitializeComponent();
}

public Form2(Image img)
{
    this.Show();
    this.pictureBox1.Image = img;
}

在“this.pictureBox1.Image=img;”行中,我得到了以下错误“类型为”System.NullReferenceException”的未处理异常。

您在
Form2(Image img)
构造函数使用中缺少
InitializeComponents()
方法调用

public Form2()
{
    InitializeComponent();
}

public Form2(Image img)
{
    InitializeComponent();
    this.pictureBox1.Image = img;
}
会有用的