PDA

Click to See Complete Forum and Search --> : Update BackGroundImage - problem


dgburton
Sep 15th, 2002, 01:07 PM
Could anyone tell me why this works the first time but not the second time it's called:

Dim wc As New System.Net.WebClient()

wc.DownloadFile("http://217.37.196.12/halfsize.jpg", _
"c:\pic.jpg")

Dim bgImage As Image = Image.FromFile("C:\pic.jpg")

Panel1.BackgroundImage = bgImage

I think it's because I'm trying to download the file again to the same filename which is in use.

Could anyone suggest a workaround?

Many thanks,

Dan

lault
Sep 19th, 2002, 04:32 PM
I would break it out into two functions,


public sub Download_Image(byval URL as string, byval filename as string)

Dim wc As New System.Net.WebClient()

wc.DownloadFile(url, filename)

end sub

public sub SetBackground(byval filename as string)

Dim bgImage As Image = Image.FromFile(filename)

Panel1.BackgroundImage = bgImage
end sub


then you can just call the second function as manay times as you want. I would also see what panel1.refresh does for you.