when I try to show my image by clicking in dropdownlist image display on picture box for first time
in i try to change the picture this error occour
System.ObjectDisposedException: 'Cannot access a disposed object.
Object name: '_1630EsdDisplayWf'.'
public void ShowMyImage(String fileToDisplay, int xSize, int ySize)
{
PictureBox pictureBoxEsdDisplay = new PictureBox();
Assembly asm = Assembly.GetExecutingAssembly();
Stream stm = asm.GetManifestResourceStream("FirstprojectDCS.FilesProjectsDcs." + fileToDisplay);
if (MyImage != null)
{
MyImage.Dispose();
}
pictureBoxEsdDisplay.SizeMode = PictureBoxSizeMode.StretchImage;
MyImage = new Bitmap(stm);
pictureBoxEsdDisplay.ClientSize = new Size(xSize, ySize);
pictureBoxEsdDisplay.Image = (Image)MyImage;
Controls.Add(pictureBoxEsdDisplay);
}
What I have tried:
image change in picture box
public void ShowMyImage(String fileToDisplay, int xSize, int ySize)
{
PictureBox pictureBoxEsdDisplay = new PictureBox();
Assembly asm = Assembly.GetExecutingAssembly();
Stream stm = asm.GetManifestResourceStream("FirstprojectDCS.FilesProjectsDcs." + fileToDisplay);
if (MyImage != null)
{
MyImage.Dispose();
}
pictureBoxEsdDisplay.SizeMode = PictureBoxSizeMode.StretchImage;
MyImage = new Bitmap(stm);
pictureBoxEsdDisplay.ClientSize = new Size(xSize, ySize);
pictureBoxEsdDisplay.Image = (Image)MyImage;
Controls.Add(pictureBoxEsdDisplay);
}
Screen scr = Screen.PrimaryScreen;
int temphigh = scr.Bounds.Height;
int tempwidth = scr.Bounds.Width;
if (ESDNO_1630 == "ESDNO1_CAUSE1")
{
ShowMyImage("1630-ESD-001.gif", tempWidth,tempHeight);
}else if (ESDNO_1630 == "ESDNO1_CAUSE2")
{
ShowMyImage("1630-ESD-001.gif", tempWidth, tempHeight);
}
else if (ESDNO_1630 == "ESDNO1_CAUSE3")
{
ShowMyImage("1630-ESD-001.gif", tempWidth, tempHeight);
}