Reusing the WebBrowser Control

Reusing the WebBrowser Control

I have found the need in several projects as of late to reuse the WebBrowser Control in .net  languages such as c#/vb.net. I have not ventured into the j# domain, but I have also played around with c++.net a little bit for various projects. There are a couple of things to keep in mind when reusing the control in different scenarios – most of which for my purposes do not include in a windows form for display purposes. For the most part making sure that there is a reference to System.Windows.Forms dll is in your References and making sure that the using or imports statements are also included this is a good first start.

WebBrowser in a Console Application

To use the WebBrowser in a Console Application – the possibly one of the first Caveats will be marking the Main function as [STAThread].


[STAThread]
static void Main() {

}


<STAThread()> _

Public Shared Sub Main()

End Sub

Msdn Article on STAThread – Why is STAThread Required

Capturing an Image

There are at least two ways to capture an image with the Web Browser,

1) Direct Screen Capture

2) IViewObject

The tricks with the two suggested previous methods vary a little, but the main issue is catching document.onComplete – which apparently can get called multiple times.

More to come in later posts…

This entry was posted in C#.net, VB.net. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *