Picturebox ImageLocation Loading

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
I have a bunch of pictureboxes and i set all their .imagelocation to Urls. So the images will load when it is in view when i scroll to them. Can i trigger a specific picturebox to load the image before its in view? Do i just do a .LoadAsync(.imagelocation) ? Or is there a command to trigger the loading. Also can you check if the picturebox is loading something?

I am trying to preload the picturebox when i am almost scrolled to it.

What happen if you call .LoadAsync on a picturebox that is already loading something?

Right now i am just calling the picturebox.loadasync(picturebox.imagelocation) if picturebox.image is nothing
 
Last edited:
Why cant the AsyncImageStatus be changed right when the LoadAsync is called? I was doing it before with a variable call Loading on each picturebox that is set before the LoadAsync was called.
If you're going to shadow the LoadAsync method anyway then it makes sense to do that, i.e. set AsyncImageStatus to Loading. Just be aware that, if the image starts loading automatically, i.e. because the ImageLocation was set and the control was visible, then the AsyncImageStatus still won't be set to Loading until the LoadProgressChanged event is raised for the first time. Even if LoadAsync is called internally in that case, it will be the PictureBox's implementation that gets called. It also means that if LoadAsync is called via a PictureBox reference rather than a PictureBoxEx reference then the new implementation is bypassed too. This is why shadowing is a bit dodgy and not full-service like overriding. If a method is not overridable then we have no choice but to shadow but it's not ideal.
 
I now keep all imagelocation empty, until LoadAsync is called. So only time image start loading is when i call it. And its triggered by scrolling so it can call it a few times since the scrolling doesnt just trigger once. If it stop loading anytime i call the loadasync, its not too good. What if i scrolled in range of a large image and stop and the image loaded halfway and i decide to scroll again, it stop it and start again Then it wont be done loading.
 
But you wouldn't stop loading halfway through because, in the code from post #14, CancelAsync is not called if the AsyncImageStatus is Loading, which it would be at that point. When PictureBox.LoadAsync is called, the first LoadProgressChanged event is raised when the image data starts to be received. There's an interval in between the call and the first event while the response from the server is awaited but once data gets received then events start getting raised. using my code from post #14, the maximum wasted effort would be that interval between LoadAsync call and the first LoadProgressChanged event raised when the first data is received. If you're never setting the ImageLocation property but rather always calling LoadAsync and passing the image URL then, if you do as I said in post #16, you'll never even waste that effort.
 
Back
Top