Resolved Picturebox events

ideprize

Well-known member
Joined
Oct 19, 2011
Messages
97
Programming Experience
10+
Hi All
Trying to implement a confirmation sequence regarding the loading of an image in a picturebox. I need to know this for once the image is loaded I am going to print it using the printdocument_printpage sub of the printdocument class. I am trying to use the picturebox events namely the picturebox1_loadcompleted event. Below is the code stream I am using. I am thinking that the loadasync(file) should initiate the event stream but that's not happening. Of course I have installed the event handlers but I guess I am missing something like "the fire command". Any insight would be greatly appreciated.

imgin = False 'boolean variable
PictureBox1.Image = Nothing
PictureBox1.WaitOnLoad = False
PictureBox1.LoadAsync("image")
Do While imgin = False
Loop
'print the pricturebox

Private Sub PictureBox1_LoadCompleted(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs) Handles PictureBox1.LoadCompleted
'signal image loaded
imgin = True
End Sub

As you can see I am trying to use a simple semaphore scheme using the loadcompleted event. I have tried the
Do While PictureBox1.Image Is Nothing
Loop
which does basically does nothing. When I saw the loadcompleted event I thought for sure this would "do the trick". Thanks in advance.
Ideprize
 
Last edited:
Thanks JohnH
Actually you solved my problem with your last post when you pointed out I didn't have to print the PictureBox. Printing the PictureBox was what set the issue up in the first place. Some times the PictureBox was not completely "full" and this would result in a "pixelated mindcraft" output. But as you pointed out all I needed to do was refer to the disk file directly by loading it into an image type variable. I still need the PictureBox display for the user but the uncertainty of the printed output is gone! I will look into the Task.Run command, however. I am going to mark the thread as resolved.
Respectfully,
Ideprize
 
Back
Top