End Google Ads 201810 - BS.net 01 --> I'm trying to make my program take a screenshot of a webbrowser after it finishes navigating and all I seem to be able to do is take a screenshot of it before it finishes navigating (a white rectangle). It's probably something very simple that I just keep missing, but am getting too annoyed to see it.

I stepped through it and apparently it takes the screenshot when the webBrowserForScreenShot is called after Navigate has been called, but no image is present. However the url is set for the webbrowser to the address it was sent by navigate. I also tried a while loop until webBrowser.ReadyState = complete, but ended up in an infinite loop. I tried adding Application.DoEvents(); as the action in the loop and then end up with a black rectangle. Btw, it does load the page after all is said and done, just too late to be a part of the screenshot. Any help would be great!

public ScreenShotWin()
{
InitializeComponent();
openWebBrowser();
}

public void openWebBrowser()
{
webBrowser1.Navigate("http://google.com");
}

private void webBrowserForScreenShot(object sender, WebBrowserDocumentCompletedEventArgs e)
{
IntPtr htmlWindow = webBrowser1.Handle;
CaptureWindowToFile(htmlWindow, "C:\\Interbank.bmp", ImageFormat.Bmp);
}

this.webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowserForScreenShot);