5 Replies - 1750 Views - Last Post: 10 April 2012 - 04:17 AM Rate Topic: ***** 1 Votes

#1 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

'System.Drawing.Image' converted to 'System.Drawing.Icon&#

Posted 09 April 2012 - 06:41 AM

Hello.
I am making a web browser using geckofx. I have put the favicon in a picture box but I have changed my mind and now I want it as the form's icon. The code for the favicon is:
        Dim oURL As Uri = New Uri(e.Uri.AbsoluteUri)
        Dim favicon As Image
        If oURL.HostNameType = UriHostNameType.Dns Then

            Try
                Dim iconURL As String = "http://" & oURL.Host & "/favicon.ico"
                Dim request As System.Net.WebRequest = HttpWebRequest.Create(iconURL)
                Dim response As HttpWebResponse = request.GetResponse
                Dim stream As IO.Stream = response.GetResponseStream
            
            favicon = Image.FromStream(Stream)
            Catch
                PictureBox1.Image = PictureBox1.ErrorImage
            End Try
            Try
                If favicon Is Nothing Then
                    Dim result As String = String.Empty
                    For Each element As GeckoElement In GeckoWebBrowser1.document.DocumentElement.GetElementsByTagName("link")
                        If element.GetAttribute("REL") = "SHORTCUT ICON" Then
                            result = element.GetAttribute("HREF")
                        End If
                    Next
                    Dim req As WebRequest = HttpWebRequest.Create(result)
                    Dim res As HttpWebResponse = req.GetResponse
                    Dim str As IO.Stream = res.GetResponseStream
                    favicon = Image.FromStream(str)
                End If
            Catch ex As Exception
            End Try
        End If
        Try
            Me.PictureBox1.Image = favicon
        Catch ex As Exception
        End Try


The favicon works fine in the picture box but i think it will look better as an icon. If i change the line Me.PictureBox1.Image = favicon to Form1.icon = favicon I get the error Value of type 'System.Drawing.Image' cannot be converted to 'System.Drawing.Icon'.

How can I get this to work?
Thanks in advance! :D

Is This A Good Question/Topic? 1
  • +

Replies To: 'System.Drawing.Image' converted to 'System.Drawing.Icon&#

#2 Plymboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-April 12

Re: 'System.Drawing.Image' converted to 'System.Drawing.Icon&#

Posted 09 April 2012 - 07:34 AM

Might be a stupid question, but if you're using GeckoFX, would it be a different language to VB.NET?
Was This Post Helpful? 0
  • +
  • -

#3 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: 'System.Drawing.Image' converted to 'System.Drawing.Icon&#

Posted 09 April 2012 - 07:41 AM

Gecko can be used in all sorts of programming.

Back to the question, how can i convert system.drawing.image to system.drawing.icon?

This post has been edited by curlyfries1999: 09 April 2012 - 08:38 AM

Was This Post Helpful? 0
  • +
  • -

#4 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 173
  • View blog
  • Posts: 1,094
  • Joined: 10-December 08

Re: 'System.Drawing.Image' converted to 'System.Drawing.Icon&#

Posted 09 April 2012 - 02:39 PM

Here:

        Dim img As Image = 'Whatever your image is...
        Dim bm As Bitmap = img
        Dim hIcon As IntPtr = bm.GetHicon
        Dim TheIcon As Icon = Icon.FromHandle(hIcon)


Was This Post Helpful? 1
  • +
  • -

#5 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: 'System.Drawing.Image' converted to 'System.Drawing.Icon&#

Posted 09 April 2012 - 03:12 PM

View PostPlymboy, on 10 April 2012 - 12:34 AM, said:

Might be a stupid question, but if you're using GeckoFX, would it be a different language to VB.NET?

GeckoFX is a control that has been distributed for many different programming platforms.

This post has been edited by DimitriV: 09 April 2012 - 03:13 PM

Was This Post Helpful? 1
  • +
  • -

#6 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: 'System.Drawing.Image' converted to 'System.Drawing.Icon&#

Posted 10 April 2012 - 04:17 AM

View PostJack Eagles1, on 09 April 2012 - 02:39 PM, said:

Here:

        Dim img As Image = 'Whatever your image is...
        Dim bm As Bitmap = img
        Dim hIcon As IntPtr = bm.GetHicon
        Dim TheIcon As Icon = Icon.FromHandle(hIcon)


Thanks! It was just what I was looking for. :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1