How to empty a picture box in c#?

  • Thread starter Thread starter Stan Huang at Taiwan
  • Start date Start date
S

Stan Huang at Taiwan

Guest
Below is my snippet to show a picture using PictureBox().

picMatcheds[picId] = new PictureBox();
picMatcheds[picId].Width = 100;
picMatcheds[picId].Height = 100;
picMatcheds[picId].Location = new Point (700, 100 * picId);
picMatcheds[picId].SizeMode = PictureBoxSizeMode.StretchImage;
string url = @"http://localhost:8099/image/" + imageDataId;
this.Controls.Add(picMatcheds[picId]);
WebClient client0 = new WebClient();
Uri url0 = new Uri(url);
client0.DownloadFile(url0, @"d:\test\testpicfile");
picMatcheds[picId].Visible = true;
var request = WebRequest.Create(@"d:\test\testpicfile");
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
picMatcheds[picId].Image = Image.FromStream(stream);
}
picMatcheds[picId].Visible = true;


It shows a picture successfully. Then, I'd like to empty it. I did it by

picMatcheds[picId].Image = null;

It seems working well, but then the trouble came. After emptying it, I'd like to display another picture using the same picMatcheds[picId], thru the original code snippet. This time, the picture can't be shown successfully.

How come?

Continue reading...
 
Back
Top