Screenshot of webbrowser control...(ie screenshot of web page in web browser control)

  • 9 years ago

    I needed Vb.NET code for capturing a screenshot of a webbrowser control........         the webbrowser may not be the first in zorder.. ie not on top.....

    i tried both PrintWindow and WM_PRINT.. but both dowsn't work for me.. i get a black screenshot with PrintWindow (even if the webbrowser is on top of other controls and focussed...)....


    code---


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim webWidth As Integer = WebBrowser1.Width
            Dim webHeight As Integer = WebBrowser1.Height
            Dim result As Boolean
            Dim webHwnd As Long
            webHwnd = WebBrowser1.Handle
            Dim bitDest As New Bitmap(webWidth, webHeight)
            Dim g As Graphics
            g = Graphics.FromImage(bitDest)
            Dim hdc As Long
            hdc = g.GetHdc()
            result = PrintWindow(webHwnd, hdc, 0)
            g.ReleaseHdc(hdc)
            g.Flush()
            MsgBox(result)
            If result Then
                PictureBox1.Image = bitDest
                bitDest.Save("c:\\bit.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
            End If
    end sub

     
     

  • 9 years ago

    Hey , The best way for u is pls download the follow link http://www.codeproject.com/KB/vb/WebCapture/WebCapture1b.zip

  • 9 years ago

    hey thnx man.. it's exactly what i need... gr8 code... 

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Memory is like an orgasm. It's a lot better if you don't have to fake it.” - Seymour Cray