Home All Groups Group Topic Archive Search About

Webbrowser drawtobitmap does not work

Author
24 Jan 2006 2:30 PM
GM
Hello,

I have visual studio 2005 on XP SP2.
I have a simple sample application using a webbrowser and 2 buttons.
Button1 loads the page
Button2 saves the screenshot
But for some reason the screenshot is always blank
Sample code:
--------------
  Private Function CreateScreenshot(ByVal Control As Control) As Bitmap
        Dim Screenshot As New Bitmap(Control.Width, Control.Height)
        Control.DrawToBitmap(Screenshot, New Rectangle(0, 0, Control.Width,
Control.Height))
        Return Screenshot
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate(New Uri("http://www.hln.be/"))
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
        Dim bm As Bitmap
        bm = CreateScreenshot(WebBrowser1)
        bm.Save("c:\temp\test.png", System.Drawing.Imaging.ImageFormat.Png)
    End Sub

Any ideas?

Author
24 Jan 2006 6:32 PM
Herfried K. Wagner [MVP]
"GM" <inva***@invalid.com> schrieb:
> I have visual studio 2005 on XP SP2.
> I have a simple sample application using a webbrowser and 2 buttons.
> Button1 loads the page
> Button2 saves the screenshot
> But for some reason the screenshot is always blank

This method doesn't work in a stable way.  I believe this fact is documented
somewhere.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>