Results 1 to 3 of 3

Thread: help - PictureBox from Web(URL) [Smoothly]

  1. #1

    Thread Starter
    Member intellilogic's Avatar
    Join Date
    Oct 2010
    Tyson's Corner, VA

    Question help - PictureBox from Web(URL) [Smoothly]

    I am using this code I got when I googled. It locks up the form for 4-10 full seconds! Very strange. I have a VERY FAST comp/connection. I am looking for better code that runs smoothly. I'd also like if it fails to load something like error.jpg or something, not just staying blank. I don't know where to throw this in the code. I have only loaded 1 PictureBox on the interface, but in the end, I want to load 6-10 on one form at one time.

    Imports System.IO
    Imports System.Net
    Imports System.Text
        Public Sub LoadPics()
            LoadWebImageToPictureBox(picCrop1, "http://www.sample.com/image.jpg")
        End Sub
        Public Function LoadWebImageToPictureBox(ByVal pb _
          As PictureBox, ByVal ImageURL As String) As Boolean
            Dim objImage As MemoryStream
            Dim objwebClient As WebClient
            Dim sURL As String = Trim(ImageURL)
            Dim bAns As Boolean
                If Not sURL.ToLower().StartsWith("http://") _
                     Then sURL = "http://" & sURL
                objwebClient = New WebClient()
                objImage = New  _
                pb.Image = Image.FromStream(objImage)
                bAns = True
            Catch ex As Exception
                bAns = False
            End Try
            Return bAns
        End Function

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: help - PictureBox from Web(URL) [Smoothly]

    Always read the documentation first. You're using a PictureBox control. It already has inbuilt functionality to asynchronously load an image from the internet. Read the MSDN documentation for the LoadAsync method.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member intellilogic's Avatar
    Join Date
    Oct 2010
    Tyson's Corner, VA

    Re: help - PictureBox from Web(URL) [Smoothly]

    Perfect, thanks

    PictureBox.WaitOnLoad = False

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width