VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
picture box from web location Posted by digitalgeek on 13 Oct 2005 at 5:02 AM
Does anybody know how to make the picture box use a picture from a web location?

Report
Re: picture box from web location Posted by iwilld0it on 13 Oct 2005 at 8:56 AM
: Does anybody know how to make the picture box use a picture from a web location?
:
:

Here is a reusable function you can use ...

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


This assumes you have these namespaces imported ...

Imports System.Net
Imports System.Windows.Forms


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

Using the function is easy ...

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

Call LoadPictureBoxFromWeb(PictureBox1, url)


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




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.