Problems with three Forms and picture box

Asked

Viewed 131 times

-1

Hi, here’s my scenario: - Configuration form (name, e-mail and a photo) - ABC form - which has a form that opens by clicking on a ABC form button - BCA form - which has a form that opens by clicking on a BCA form button

The ABC form or the BCA form will be called based on the choice made in the Configuration form, via radio Buttons.

In this configuration form is also made the choice of a jpg/png image that the user will look for on the pc itself. After all the filled data and chosen photo in this configuration form, the user will click a "Start" button, where based on the choice of the ABC or BCA ratio button will open their respective forms. Also, the image will be saved in a folder with the logo name.jpg.

In the ABC form or BCA form there is also a picture box where the image saved in folder X (C: X Img logo.jpg) will be loaded. That’s where my problem comes in. Both ABC form or BCA has a button that takes in another form, where will also be loaded the same picture box... But it triggers an error, because it says that the image is already loaded.

Note: To finish the configuration form I use this. Visible = false; And also for the ABC and BCA forms. I think that’s why it gives this error, because the image is already with a space allocated in memory..

You could help me?

private void pictureBox_logo_Click(object sender, EventArgs e)
{
 OpenFileDialog file = new OpenFileDialog();
 file.Filter = "PNG|* .png|BMP|*.bmp|JPG|*.jpg;*.jpeg";
 if (file.ShowDialog() == DialogResult.OK)
{
 pictureBox_logo.ImageLocation = file.FileName
}
 pictureBox_logo.Image.Save(@"C\tools\img\logo.jpg");

}

And in the other form (which will open with the choice of radio button ABC or BCA)

public partial class frmPrincipal : Form
 {
    public frmPrincipal()
    {
        InitializeComponent();


        picturebox_principal.Load(@"C:\tools\img\logo.jpg");
     }
}
  • Without the code where the error occurs becomes difficult, post the code.

  • Ready edited... I hope you can understand... In what I had written can understand a little better my scenario... The image is loaded into a form, when I try to open another form through a button and load the same image, it triggers an error saying that the image is already in use

1 answer

1


Using the available code there is at no time the image assignment to the Picturebox component, just when running the line that has the . Save() null reference error occurs.

Follows modified code:

using (OpenFileDialog openDialog = new OpenFileDialog())
{
     openDialog.Filter = "PNG|* .png|BMP|*.bmp|JPG|*.jpg;*.jpeg";
     if (openDialog.ShowDialog() == DialogResult.OK)
         pictureBox1.Image = Image.FromFile(openDialog.FileName);

     pictureBox1.Image.Save(@"C:\tools\img\ip.png");
}

Loading the image in the other Picturebox will be done in the same way:

public Form2()
{
      InitializeComponent();
      pictureBox2.Load(@"C:\tools\img\ip.png");
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.