|
> VB2005にてサイトのアイコン(favicon.pngイメージ)をwebbrowserで取得したいのですが、
favicon.icoではないのですか?
favicon.icoなら例えば次のように取得できます。(webbrowserではありませんが...)
Imports System.Net
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WebBrowser1.GoHome()
End Sub
Public Function GetFavicon(ByVal Url As String) As Image
Dim Img As Image = Nothing
Dim Req As WebRequest = Nothing
Dim i As Integer = Url.LastIndexOf("/")
Url = Url.Substring(0, i) & "/favicon.ico"
Try
Req = WebRequest.Create(Url)
Using myResponse As WebResponse = Req.GetResponse()
Using myStream As Stream = myResponse.GetResponseStream()
Img = Image.FromStream(myStream)
End Using
End Using
Return Img
Catch ex As Exception
Return Nothing
End Try
End Function
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Dim f As New Form
f.BackgroundImage = GetFavicon(e.Url.ToString)
f.Show()
End Sub
End Class
|