Imports System.Runtime.InteropServices Public Class Form1 Enum DVASPECT As Integer CONTENT = 1 THUMBNAIL = 2 ICON = 4 DOCPRINT = 8 End Enum <DllImport("ole32.dll")> _ Public Shared Function OleDraw( _ ByVal pUnk As IntPtr, _ ByVal dwAspect As Integer, _ ByVal hdcDraw As IntPtr, _ ByRef lprcBounds As Rectangle) _ As Integer End Function Dim WithEvents WebBrowser1 As New WebBrowser Dim WithEvents Button1 As New Button Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WebBrowser1.Dock = DockStyle.Fill Me.Button1.Text = "キャプチャ" Me.Controls.AddRange({Button1, WebBrowser1}) Me.WebBrowser1.GoHome() End Sub Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted Me.Button1.Enabled = True End Sub Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating Me.Button1.Enabled = False End Sub Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim BodyStyle As String = Me.WebBrowser1.Document.Body.Style Dim BrowserSize As Size = Me.WebBrowser1.Size Me.WebBrowser1.Visible = False Me.WebBrowser1.Document.Body.Style &= "overflow-x:hidden;overflow-y:hidden" 'スクロールバーを消す Dim ImageRect As Rectangle = Me.WebBrowser1.Document.Body.ScrollRectangle Me.WebBrowser1.Size = ImageRect.Size Using WebImage As New Bitmap(ImageRect.Size.Width, ImageRect.Size.Height) Using g As Graphics = Graphics.FromImage(WebImage) Dim pUnk As IntPtr = Marshal.GetIUnknownForObject(Me.WebBrowser1.ActiveXInstance) Dim hDc As IntPtr = g.GetHdc OleDraw(pUnk, DVASPECT.CONTENT, hDc, ImageRect) g.ReleaseHdc(hDc) Marshal.Release(pUnk) End Using WebImage.Save(My.Computer.FileSystem.SpecialDirectories.Desktop & "\WebImage.bmp") End Using Me.WebBrowser1.Size = BrowserSize Me.WebBrowser1.Document.Body.Style = BodyStyle Me.WebBrowser1.Visible = True End Sub End Class