picture box from web location - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

picture box from web location

digitalgeekdigitalgeek Posts: 59Member
Does anybody know how to make the picture box use a picture from a web location?

Comments

  • iwilld0itiwilld0it Posts: 1,134Member
    : Does anybody know how to make the picture box use a picture from a web location?
    :
    :

    Here is a reusable function you can use ...

    [code]
    Function LoadPictureBoxFromWeb(ByVal surface As PictureBox, ByVal url As String) As Boolean
    If surface Is Nothing Then
    Return False
    End If

    Try
    Dim request As WebRequest = WebRequest.Create(url)
    Dim response As WebResponse = request.GetResponse()

    surface.SizeMode = PictureBoxSizeMode.AutoSize
    surface.Image = Image.FromStream(response.GetResponseStream)
    Catch
    Return False
    End Try

    Return True
    End Function
    [/code]

    This assumes you have these namespaces imported ...

    [code]
    Imports System.Net
    Imports System.Windows.Forms
    [/code]

    You may or may not have import the System.Drawing namespace.

    Using the function is easy ...

    [code]
    Dim url As String = "http://www.someaddress.com/image.jpg"

    Call LoadPictureBoxFromWeb(PictureBox1, url)
    [/code]

    Of course there is alot more room to make this more robust, but this should be a good starting point.

Sign In or Register to comment.