I have to comment on my
previous question and the answered that I have chosen
The answer were good if the pictureBox1 is attached to only one image file
But
If the the pictureBox1 is attached to more than one file , I still can not delete those image files
Therefore I preferred to use the filestream method, I used it and it were much better than the
following
pictureBox1.Image = Image.FromFile(FruitName[0]+".jpg");
img = pictureBox1.Image;
pictureBox1.Image = null;
img.Dispose();
img = null;
if(File.Exists(FruitName[0] + ".jpg")) File.Delete(FruitName[0]+".jpg");
The following is much better
Private void UpButtonClick((object sender, EventArgs e)
{
j=…..
fs = new System.IO.FileStream(FruitName[j]+ ".jpg", FileMode.Open, FileAccess.Read);
pictureBox1.Image = System.Drawing.Image.FromStream(fs);
fs.Close();
}
Private void DownButtonClick((object sender, EventArgs e)
{
j=…..
fs = new System.IO.FileStream(FruitName[j] + ".jpg", FileMode.Open, FileAccess.Read);
pictureBox1.Image = System.Drawing.Image.FromStream(fs);
fs.Close();
}
private void ExitClick(object sender, EventArgs e)
{
for (i = 0; i < TotalFruit; i++)
{
if(File.Exists(FruitName[i] + ".jpg"))
File.Delete(FruitName[i] + ".jpg");
}
Application.Exit();
}