Sofia Rodrigues

Sofia Rodrigues

  • NA
  • 23
  • 1.6k

Parameter is not valid - "pictureBox.Show()"

Mar 14 2019 5:44 AM
I'm making a TIFF viewer with a picture box and buttons for going trought the pages of multi page files.
 
When I open a file for the first time, all works great, then I close it. But when I open a new file, after closing the previous one, I get an error saying "Parameter is not valid" at the line "pbtiff.Show()".
 
This is my code for opening the file:
  1. private void openToolStripMenuItem_Click(object sender, EventArgs e)  
  2. {  
  3.    pbtiff.Hide();  
  4.    OpenFileDialog dialogo = new OpenFileDialog();  
  5.    dialogo.Title = "Search files";   
  6.    dialogo.InitialDirectory = @"E:\";   
  7.    dialogo.Filter = "PDF Files(.pdf)|*.pdf|Image Files (.bmp,.jpg,.png,.tiff,.tif) |*.bmp;*.jpg;*.png;*tiff;*tif";   
  8.    DialogResult answer = dialogo.ShowDialog();  
  9.    if (answer == DialogResult.OK)  
  10.    {  
  11.       string fullPath = dialogo.FileName;   
  12.       openFile = fullPath;  
  13.       using (var fileStream = new FileStream(ficheiroaberto, FileMode.Open))  
  14.       {  
  15.          type = Path.GetExtension(caminhoCompleto);  
  16.          if (type == ".tif" || type == ".tiff")  
  17.          {  
  18.             up.Visible = true;  
  19.             up.Enabled = false;  
  20.             down.Visible = true;  
  21.             pbtiff.Show(); -> the error is here, when I open the file for the 2nd time  
  22.             if (pbtiff.Image != null)  
  23.             {  
  24.                pbtiff.Image.Dispose();  
  25.             }  
  26.             pbtiff.Image = System.Drawing.Image.FromStream(fileStream);  
  27.             SplitTiffFinal(fileStream);  
  28.             filestiff = GetFilesFinal();  
  29.             up.Visible = true;  
  30.             up.Enabled = false;  
  31.             down.Visible = true;  
  32.          }  
  33.       }  
  34.    }  
  35. }  
Can you help me figure out what is the probem, if it works the first time?

Answers (2)