Webbrowser drawtobitmap does not work

G

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?
 
H

Herfried K. Wagner [MVP]

GM said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top