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:
- private void openToolStripMenuItem_Click(object sender, EventArgs e)
- {
- pbtiff.Hide();
- OpenFileDialog dialogo = new OpenFileDialog();
- dialogo.Title = "Search files";
- dialogo.InitialDirectory = @"E:\";
- dialogo.Filter = "PDF Files(.pdf)|*.pdf|Image Files (.bmp,.jpg,.png,.tiff,.tif) |*.bmp;*.jpg;*.png;*tiff;*tif";
- DialogResult answer = dialogo.ShowDialog();
- if (answer == DialogResult.OK)
- {
- string fullPath = dialogo.FileName;
- openFile = fullPath;
- using (var fileStream = new FileStream(ficheiroaberto, FileMode.Open))
- {
- type = Path.GetExtension(caminhoCompleto);
- if (type == ".tif" || type == ".tiff")
- {
- up.Visible = true;
- up.Enabled = false;
- down.Visible = true;
- pbtiff.Show(); -> the error is here, when I open the file for the 2nd time
- if (pbtiff.Image != null)
- {
- pbtiff.Image.Dispose();
- }
- pbtiff.Image = System.Drawing.Image.FromStream(fileStream);
- SplitTiffFinal(fileStream);
- filestiff = GetFilesFinal();
- up.Visible = true;
- up.Enabled = false;
- down.Visible = true;
- }
- }
- }
- }
Can you help me figure out what is the probem, if it works the first time?