Feb 14, 2013

Activate Edit Mode in WebBrowser Control (VB.NET)

Web browser control is basically used to navigate the web pages. But it also provide the functionality to customize the content. For e.g. If we want to create an Emailer wherein we want to apply styles to our content and send the Email programmically then WebBrowser Control allow us to Edit / Create the content, after which we can view it's HTML and send it as HTML body in our Email program. We can also implement customized HTML Editor with this functionality. By default, design mode of the WebBrowser Control is set to Off. I found two methods for setting WebControl's design mode to On.

First Method is using the mshtml library.
For e.g.
Import mshtml ' Import mshtml library at the top.

Dim doc As IHTMLDocument2
doc = DirectCast(webBrowser1.Document.DomDocument, mshtml.IHTMLDocument2)
doc.designMode = "On"

This above example required to add mshtml library in project. Usually mshtml is installed with .NET framework
You can found / copy the library in "C:\Program Files\Microsoft.NET\Primary Interop Assemblies" to install the assembly.

Second Method is rather easy. I found it here
Dim axObj As New Object
axObj = WebBrowser1.ActiveXInstance
axObj.document.designmode = "On"    ' Intellisense won't be available for this.

Hope, it may be useful.


Blogs | About Me | My Projects | Contact Me