I have one tabcontrol on a form with two tabpages and two picture boxes in each. I use rightclick to open a context menu for selecting a file to display in each picturebox. When I do it with one picturebox it is OK. However, after selecting a file for other picturebox fails with an exception "Parameter not valid".
Basically, I do this:
System::Void DPrint::Form1::toolStripMenuItem1_Click(System::Object^ sender, System::EventArgs^ e)
{
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
if (imgToDisplay != nullptr)
{
delete imgToDisplay;
}
PictureBox^ MyPictureBox = safe_cast<PictureBox^>(this->contextMenuStrip2->SourceControl);
imgToDisplay = gcnew System::Drawing::Bitmap(this->openFileDialog1->FileName);
MyPictureBox->Image = safe_cast<Image^>(imgToDisplay);
}
}
Any idea what is wrong? Thank you so much.
Solved. I was deleting the last image to be displayed so I have removed an if statement and everything works. Thank you.