简体   繁体   中英

How to assign a image From Form1 to Form2 Picturebox

I am creating Image editor using C# Windows application, and now I have problem to assign a image to Form2 picturebox from Form1.

I am trying shown below code
The below code is written in Form1.cs page

    if(flag==0)
    {
        Form2 f2 = new Form2(glb_image_list_arr[0]);
        f2.Show();                
    }

And the below code is written in Form2.cs page

public Form2()
{
    InitializeComponent();
}

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

In the " this.pictureBox1.Image = img; " line, I got the following error " An unhandled exception of type 'System.NullReferenceException "

You are missing InitializeComponents() method call in Form2(Image img) constructor use

public Form2()
{
    InitializeComponent();
}

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

will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM