A simple problem but I can't see an obvious answer.
I want to detect when a user's image hasn't loaded for any reason. The obvious way seems to check if the image is ErrorImage but I can't work out how. Any assistance gratefully received.
A simple problem but I can't see an obvious answer.
I want to detect when a user's image hasn't loaded for any reason. The obvious way seems to check if the image is ErrorImage but I can't work out how. Any assistance gratefully received.
How can I detect when PictureBox is showing ErrorImage?
Rtalan
Thank you Lucian for your assistance - the right way to do it is:
If e.Error Is Nothing Then True 'Good picture Else False 'Bad picture End Ifsql1
Have you tried listening to LoadCompleted event
Andrej
carlp22
Thank you Lucian,
I have got there eventually. I find that the Cancelled property is an unreliable method of determining if the ErrorImage is displayed - it is set to False even if an illegal file type is loaded.
The Error property seems a reliable indicator but being new to the .net game I find I can't test against it easily as the property is only valid if there is an error. So my final code looks bizarre but works.
Private Sub PictureBox1_LoadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles PictureBox1.LoadCompleted Try If e.Error.Message <> "" Then PictureBox1.Visible = False 'Erroneous picture Catch ex As Exception True 'Good picture End Try End Subprozac11
Unfortunately it appears that the LoadCompleted event is created whether the image is loaded successfully or not.
Thank you for your suggestion though.
molemenacer
You should get an error:
The LoadCompleted occurs only when the image is loaded asynchronously using one of the LoadAsync methods and WaitOnLoad is false. If the image-load is cancelled by calling the CancelAsync method the Cancelled property of the AsyncCompletedEventArgs will be set to true. If an exception or error occurs during the load process, it will be caught and the Error property of the AsyncCompletedEventArgs will contain the exception information.
XBTester