Page 1 of 1

program detects picture box error/

Posted: Tue Jul 06, 2010 8:04 pm
by zachman61
how can i make it show a message box if the picture box image does not load
example a user inputs
a url like tis
example.com/img.jpg
but thats not a real link so it brings up the boxed 'X'
how can i do it?

Re: program detects picture box error/

Posted: Tue Jul 06, 2010 8:54 pm
by mandai
Code: Select all
        Dim data As Byte()

        Dim wc As WebClient = New WebClient()
        Try
            data = wc.DownloadData("http://localhost/image.png")
        Catch ex As Exception
            MsgBox("error: " & ex.Message)
            Return
        End Try

        Dim ms As MemoryStream = New MemoryStream(data, 0, data.Length, False, True)

        Try
            PictureBox1.Image = Image.FromStream(ms)
        Catch ex As Exception
            MsgBox("error: " & ex.Message)
        End Try

        ms.Close()

Re: program detects picture box error/

Posted: Wed Jul 07, 2010 4:00 am
by zachman61
i mean if its a broken url it doesnt show it
so like a working is this
www.example.com/pic.png
and a broken is this
www.example.com/plc.png
the broken will not show but if the working is typed in no message box will popup

Re: program detects picture box error/

Posted: Wed Jul 07, 2010 11:30 am
by mandai
Those links are both valid, if the image is not found the webclient will return an error.

Re: program detects picture box error/

Posted: Wed Jul 07, 2010 10:26 pm
by zachman61
if the picture works the thing will still show it though