program detects picture box error/

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts Page 1 of 1
Contributors
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

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?
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

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()
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

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
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Those links are both valid, if the image is not found the webclient will return an error.
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

if the picture works the thing will still show it though
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
5 posts Page 1 of 1
Return to “Tutorial Requests”