Page 1 of 1

imagelist from url

Posted: Fri Mar 11, 2011 7:30 am
by dan2130
hello, i want to know if its possible to add a new picture into an imagelist from a url by example the software get the picture from the web site and add the picture as the image name and after that the picture is usable with listview.
i have tryed to explain the best as possible but if you have some questions you can ask it to me
thanks in advance.

Re: imagelist from url

Posted: Fri Mar 11, 2011 7:46 am
by MrAksel
I know how to do it, but I'm on m iPod, I'm back in 20 minutes. I understand what you need

Re: imagelist from url

Posted: Fri Mar 11, 2011 7:49 am
by dan2130
ok thanks

Re: imagelist from url

Posted: Fri Mar 11, 2011 8:10 am
by MrAksel
If you have a webbrowser control on your form you could take the Images propertynfrom the current HtmlDoument property of the browser. Then you could get the src attribute of each image and load that into the imagelist. I will get some code soon
Here is the code for adding all the images to ImageList1. You can so use that imagelist in your listview
Code: Select all
    For Each Image As HtmlElement In WebBrowser1.Document.Images

            Dim URL As String = Image.GetAttribute("src")

            Try
                Dim NewImage As Image
                Dim ImageStream As Stream
                Dim Request As HttpWebRequest
                Dim Response As HttpWebResponse

                Request = HttpWebRequest.Create(URL)
                Response = Request.GetResponse()
                ImageStream = Response.GetResponseStream

                NewImage = System.Drawing.Image.FromStream(ImageStream)

                ImageList1.Images.Add(NewImage)
            Catch ex As Exception
                MsgBox("Failed to add the image from the url """ & URL & """.")
            End Try
        Next

Re: imagelist from url

Posted: Fri Mar 11, 2011 7:30 pm
by dan2130
sorry but i dont know how i can add the picture in the listview

Re: imagelist from url

Posted: Fri Mar 11, 2011 7:51 pm
by dan2130
sorry i have found i have edited the line :
ImageList1.Images.Add(NewImage)
to :
ImageList1.Images.Add("Picture name", NewImage)

and after we can add the picture with the items with this code :
Dim str(3) As String
Dim itm As ListViewItem
str(0) = "test111" 'First column
str(1) = "aaaaa" ' second column
str(2) = "sssss" ' third
itm = New ListViewItem(str)
itm.ImageKey = "the picture name"
ListView1.Items.Add(itm)

Re: imagelist from url

Posted: Fri Mar 11, 2011 8:22 pm
by MrAksel
Yea, sorry, but you got it. Please lock your topic now