0
Answer

Screenshot of webbrowser control...

Prasanth

Prasanth

16y
2.6k
1
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