Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a screenshot of the web browser control?

There are a lot threads about this but none of them were clear and none I tried actually even worked right.

What is the code to get the contents of the entire web browser control (even that which is off screen)?

It looks like they did have:

webBrowser1.DrawToBitmap(); // but its unsupported and doesnt work
  1. 3rd party api - not wasting my time
  2. .DrawToBitmap and nonanswer-links
  3. 100 wrong answers
  4. just takes a screenshot
like image 771
user1873073 Avatar asked Jan 05 '13 01:01

user1873073


1 Answers

Try to make sure you are calling the method in the DocumentCompleted event.

webBrowser1.Width = wb.Document.Body.ScrollRectangle.Width;
webBrowser1.Height = wb.Document.Body.ScrollRectangle.Height;

Bitmap bitmap = new Bitmap(webBrowser1.Width, webBrowser1.Height);
webBrowser1.DrawToBitmap(bitmap, new Rectangle(0, 0, webBrowser1.Width, webBrowser1.Height));
like image 64
scartag Avatar answered Sep 17 '22 03:09

scartag