Reputation: 1866
In DocumentCompleted event handler, I try to take snap shots of certain pages, for some pages, the snapshot is perfectly taken, BUT, for other pages (e.g. the last page) a blank snapshot is taken, despite the fact that in the Browser WinForm I see content in the page!!! any idea what might be the problem?
I am trying to Capture snapshot of my WebBrowser control using the following code:
private void GetSnapshot(string nameSuffix, ImageFormat format)
{
string dateTimeNow = DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss-tt");
string imageName = string.Format("{0}_{1}_{2}.{3}", websiteName, nameSuffix, dateTimeNow, format);
using (var bmp = new Bitmap(ieBrowser.Width, ieBrowser.Height))
{
Trace.TraceInformation("Saving screenshot to '{0}'", imageName);
ieBrowser.DrawToBitmap(bmp, new Rectangle(0, 0, ieBrowser.Width, ieBrowser.Height));
bmp.Save(imageName, format);
}
}
Upvotes: 1
Views: 1193
Reputation: 1866
I solved it by creating a new dummy thread, make it wait for a few seconds and then return. (so the Control thread is not blocked).
turns out that webbrowser needs a small amount of time to actually render the page after final DocumentCompleted event is fired
Upvotes: 1