activate edit mode in .NET 2.0 Webbrowser Control

I am playing a little bit with the webbrowser control which is new in Winforms 2.0. Usally this is a wrapper around the mshtml control. It semes that microsoft have changed and dropped some funtctions like the ability to edit the html content. This is quite usefull in MSHTML cause you can implement your own HTML editor in a application.

This is done with the designmode property. But i didnt find it, and also object browser does not show it. Should work like

doc = WebBrowser1.Document
doc.DesignMode = "Off"

But the .NET way like

Dim doc As HtmlDocument = WebBrowser1.Document

does not give you the designmode property. I tryed to cast the htmldocument to mshtml.idocument2 but nothing.

Then i found the property activexinstance and now i got it

Dim axObj As New Object
axObj = WebBrowser1.ActiveXInstance
axObj.document.designmode =
"On"

Published Wednesday, July 13, 2005 8:09 PM by preishuber

Comments

# re: activate edit mode in .NET 2.0 Webbrowser Control

Sunday, June 04, 2006 7:33 AM by Sunil
Hi,
I'm using webbrowser 2.0 control in my project.  The DocumentComplete fires multiple times for a given page using webbrowser.Navigate().  Is there any way to ensure that when the document is fully downloaded on client side and then act accordingly?

Regards,
Sunil

# re: activate edit mode in .NET 2.0 Webbrowser Control

Wednesday, June 21, 2006 12:39 PM by James
Hi - I really don't know. What I need to know is how to detect an element click  ( such as an image ) when designmode = "On", i can attach the event but find that afterwhich I cannot edit it anymore.

# re: activate edit mode in .NET 2.0 Webbrowser Control

Wednesday, June 28, 2006 5:48 PM by Anthony Wieser

Dim axObj As New Object

axObj = WebBrowser1.ActiveXInstance

axObj.document.designmode = "On"

What's the type of the axObj?  do you know, since I'd like to do it in C++, instead of VB.

# re: activate edit mode in .NET 2.0 Webbrowser Control

Sunday, December 17, 2006 2:20 PM by Elan Hasson

Do a .GetType().ToString() on object and it'll tell you the type.

# re: activate edit mode in .NET 2.0 Webbrowser Control

Wednesday, December 20, 2006 6:54 PM by Tom Couvret

I'm trying to get this going as well in C#.

The type is System.__ComObject.

Need to cast it to something that has the document property, otherwise axObj.document.designmode wont compile.

# re: activate edit mode in .NET 2.0 Webbrowser Control

Wednesday, April 18, 2007 11:58 PM by Matt

This doesnt work i get MemberMissing error

# re: activate edit mode in .NET 2.0 Webbrowser Control

Monday, August 20, 2007 11:13 AM by Mahroof

Hi,

I'm using webbrowser 2.0 control in my project.  The DocumentComplete fires multiple times for a given page using webbrowser.Navigate().  Is there any way to ensure that when the document is fully downloaded on client side and then act accordingly?

Regards,

Sunil

-----------------

Sunil, you can put your code on the event DocumentComplete

# re: activate edit mode in .NET 2.0 Webbrowser Control

Thursday, September 20, 2007 5:10 PM by Chris H

The document seems to be fully loaded when ReadyState == WebBrowserReadyState.Complete

# re: activate edit mode in .NET 2.0 Webbrowser Control

Saturday, November 10, 2007 10:11 AM by phyrrix

just try insert this code:

Dim doc As HTMLDocument = WebBrowser1.Document

doc.designMode = "On"

it may doesn't appear when you type using Code Completion. And doesn't error even you type it manual. It works perfectly when you debug it. just try it

# re: activate edit mode in .NET 2.0 Webbrowser Control

Wednesday, April 02, 2008 11:09 AM by Alan Heywood

In c# you can do it as follows:

IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;

doc.designMode = "On";

# re: activate edit mode in .NET 2.0 Webbrowser Control

Wednesday, July 16, 2008 3:25 AM by joe

Dim doc As mshtml.IHTMLDocument2 = WebBrowser1.Document.DomDocument

doc.designMode = "On"

this is the best way ive found in vb.net

# re: activate edit mode in .NET 2.0 Webbrowser Control

Tuesday, December 02, 2008 1:41 PM by Phydeaux

Don't forget to set a reference to mshtml.dll and a "using mshtml" (in C#) at the beginning ... Then everything works fine.

# re: activate edit mode in .NET 2.0 Webbrowser Control

Tuesday, January 20, 2009 3:42 AM by markac

HtmlDocument doc = webBrowser1.Document.OpenNew(false);

doc.ExecCommand("EditMode", false, null);

Leave a Comment

(required) 
(required) 
(optional)
(required)