Browsers Wrapper ( Mozilla IE )






3.35/5 (7 votes)
Sep 2, 2007
2 min read

98021

3629
Describe a wrapper to render html page with mozilla or IE

Introduction
If you want to embbeded a web browser in your application,
with dotnet 2.0 there's a new control WebBrowser
( A good article about WebBrowser ) .it's the engine of Internet Explorer.
I discover recently there's an Mozilla ActiveX Plug-in, so I have tried to make a c# wrapper class to have the choose between Internet Explorer , and Mozilla to render the Html page.
This article will show about to use the Mozilla ActiveX, and how to have both IE , and Mozilla.
I don't go really inside the Mozilla Active X, may be for a update of this article.
I make a small test application, with the two html rendering objet,
I take two screenshots:
One with IE, and the second why Mozilla.
To make the different between the 2 browser , look the context menu.
Internet Explorer :
Mozilla :
Installing the Mozilla ActiveX
Install the Mozilla ActiveX Plug-in.Click on the toolbox with the right button , choose Items.
You will find in Com object this line MozillaBrowser Class underlined red.


So when you have selected it , a new icon appear in the toolbox:
Using the code
The class WrapperWebBrowser.cs
have
// The constructor public WrapperWebBrowser( ref AxMOZILLACONTROLLib.AxMozillaBrowser moz, ref System.Windows.Forms.WebBrowser ie ) public enum EnumTypeBrowser { IE, MOZILLA }; // You can set , or get the TypeBrowser // Exemple TypeBrowser = EnumTypeBrowser.IE public EnumTypeBrowser TypeBrowser; // Set the delegate when the document complete downloaded public void SetDocumentCompleteEvent(DelegateDocumentComplete docCompleteEvent) // Set the url of the browser web. public void Navigate(string url)
If you want to use the WrapperWebBrowser.cs
you have to make
a WebBrowser
and axMozillaBrowser
WrapperWebBrowser wrapperWebBrowser = null; public Form1() { InitializeComponent(); wrapperWebBrowser = new WrapperWebBrowser(ref this.axMozillaBrowser1,ref this.webBrowser1); wrapperWebBrowser.SetDocumentCompleteEvent(DocumentComplete); } private void DocumentComplete(string url) { this.Text = url; }
If you change the property wraperWebBrowser.TypeBrowser then the window of the browser you choose will be visible and
the other browser window will be not visible of course.
Points of Interest
There's some difference between WebBrowser and AxMozillaBrowser, but they are quite similar .
There's Navigate in each, the name of the callback when the Document is complete change a little bit:
mozillaBrowser.DocumentComplete;
IEBrowser.DocumentCompleted;
private void webBrowser_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
private void axMozillaBrowser_DocumentComplete(object sender,
AxMOZILLACONTROLLib.DWebBrowserEvents2_DocumentCompleteEvent e)